0

I have two containers (A and B) running Node + MongoDB. A contains restricted endpoints that require a valid token in order to read + write from the database. B will contain public endpoints that have no request requirements and allow anyone to read certain documents from the database.

The endpoints exposed in both A and B should interact with the same database. I'm not sure how to do this when it comes to MongoDB.

I'm defining the schema / model for the collection in container A, like so:

const mongoose = require('mongoose');
const Project = new mongoose.Schema({ ... });

From container B, all I want to do is to be able to sift through all Projects in the database. I don't think I'm supposed to create the same schema in this new container.

It's important to note that container B is successfully connected to the same DB as container A. It's just a matter of sifting through it via mongoose.

TL;DR: How can I access container A's db from container B, where I haven't registered any models? I'm pretty new to this so any info would be helpful.

1
  • you probably should run mongo in another container and link (using --link )both node containers to it, that would be much cleaner solution Commented Jun 8, 2016 at 9:26

1 Answer 1

2

you can use docker-compose.yml like

mongodb:
 image: mongo
dockera:
 links:
   - mongodb:mongodb
dockerb:
 links:
   - mongodb:mongodb

then you containera and containerb will connect the same mongodb

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.