How to access the same collection from different Meteor apps in one DB

I’d like to connect 2 meteor apps to the same database, and have access to the collections on that database from both apps.

Should I define my collections on both apps with the same schemas, or is one enough? And in that case, how do you get access to the collection variable for methods?

Can I simply do this twice:

const MyCollection = new Mongo.Collection('myCollection');

Is the 'myCollection' the unique identifier for that collection on the database?

Yup that should work :thumbsup: Yeah, ‘myCollection’ is the name the Collection gets in Mongo.
Try downloading Studio3T maybe, it’ll give you a good overview of what’s in your database, easier to use than the commandline :wink:

Simple-schema doesn’t affect the actual Mongo database, it just validates the fields before you insert them. So if you don’t use the same schema on both instances, you could insert something from one of them that could be invalid for the other one. Same with the Collection object and methods, they don’t have anything to do with MongoDB, they’re just in Meteor. So either copy-paste, or if you want to do it properly, create a Meteor package with them and add it to both your projects.

1 Like

Awesome, exactly what I wanted to know :slight_smile: Thanks!