How can I share MongoDB collections between Meteor apps?

export MONGO_URL=mongodb://localhost:3002/meteor

Then run meteor app, it will change the default database meteor uses. So share databases or collections won't be a problem! For administrative reason, I would use a individual MongoDB server managed by myself other than using meteor's internal MongoDB.


A reasonable question and probably worth a discussion in excess of this answer:

The MongoDB connection is handled by the Meteor application process itself and this is - as far as I read and understood - part of Meteors philosophy targeting an approach that might be described like: One data source serves one application belonging to it but many clients subscribing to it.

This in mind, combining "admin" and "client" clients in one application (i.e. your Meteor app) is probably the preferred way.

From a server administrative view, however, connections are handled by Meteor in that way that there is always the default local data source which resides in your project directory (.meteor/local/db, try meteor mongo --url to obtain the mongo connection string while the meteor application process is running). But nevertheless one may specify an optional data source string for deployment purposes like described in these deployment instructions.

So you would need to choose a somewhat creepy way of "local development deployment" for your intended setup to get working. Or you go and hack the sources and... no, forget it. You probably want your application and clients to take advantage of e.g. realtime UI updates (publish) and that is why the Meteor application is tied to an "application data source" and vice-versa by now. When connecting from another app, events that trigger changes in the model would not be transported across those applications. The mongoDB instance itself of course isn't aware of that.

I'm sure the core team won't expose the data source connection to a configuration section for considered reasons unless they extend their architecture with some kind of module concept which provides a common service layer of core Model/Collections abstraction across Meteor instances - at least supporting awareness of publish/subscribe events.


Try this DDP test I hacked together for a way to bridge two apps (server A and B).

Both servers can manipulate data, but data is only stored in one collection on server A.

See this link as well