9

This kind of question has been asked before: How can I share MongoDB collections between Meteor apps?

However, the answer is not clear.

I need to have a Meteor public app and the Administration app separate (for many reasons, but mainly security and code management).

Using the accepted answer: export MONGO_URL=mongodb://localhost:3002/meteor seems reasonable, but below another user 'matthias' points out "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."

How does one trigger the 'other' meteor app to reevaluate the events/triggers from the MongoDB? Meaning simply if I make a change in the administration module, how can I make the public site reflect those changes? Assuming that is what was meant. Also is there any other functionality that will be lost by this method?

Thanks

Community
  • 1
  • 1
mfr
  • 149
  • 3
  • 11
  • You can make a change in the database via the mongo console, and the Meteor app will still pick it up, and very quickly if it observes the DB via oplog tailing. – Dan Dascalescu Nov 28 '14 at 12:55
  • So you are saying cross-app updates are not an issue? I was under the impression that each Meteor App is closely related to its MongoDB instance. Not sure it makes sense that other Meteor Apps would 'listen' to 'other' mongo collections. – mfr Nov 28 '14 at 15:14
  • 2
    This isn't an issue. Mongodb instances are in no way tied to an application. As long as they are sharing the same instance via MONGO_URL all of the magic will happen the way you want it to. – David Weldon Nov 28 '14 at 16:32
  • Did you find any solution for this? – Muhammad Usama Mashkoor Jun 30 '22 at 15:13

1 Answers1

10

The answer is that you don't have to do anything. As long as the apps use the same database (as identified by the MONGO_URL), they will respond reactively to changes in the data.

In fact separating your app into a front-end and a back-end is a good strategy, as outlined in this video, Why you should split your meteor app.

You can even use the mongo shell to update/insert/delete documents in the database, and the publications will pick them up.

Dan Dascalescu
  • 143,271
  • 52
  • 317
  • 404
  • 3
    Heads-up when inserting directly into MongoDB though... IDs are different than from docs inserted via Meteor. – Adam Monsen Nov 29 '14 at 04:31
  • Hey , I am making the same thing as mentioned by mfr in his question. I am getting one problem when ever I insert data in MongoDb my app does not reflect the inserted data automatically I always need to refresh it manually in order to see the new inserted data in my Ui.here is my :- process.env.MONGO_URL = 'mongodb://localhost:27017/test_db'; – sid Jul 16 '15 at 09:01
  • @sid: hard to diagnose that and besides the scope of this answer. You should check your subscriptions, esp. if you use iron-router, and post a new question if you still need help. – Dan Dascalescu Jul 16 '15 at 10:39
  • Hey Dan, have a look on my new question.Here is its link :- http://stackoverflow.com/questions/31472976/push-notification-integration-in-meteor – sid Jul 17 '15 at 09:48