0

This question has been asked multiple times, here and here, and the answer to get this working is fairly straight forward: add an environmental variable to your bash_profile and all Meteor instances on your localhost will share that MONGO_URL.

What I've noticed however is that while this may be the case, there's quite a bit of latency in the "reactivity" of Meteor. I've tested this with two very lean Meteor apps, with empty collections. Inserting a document to a collection from one Meteor app, where my second app is querying that same collection and printing out a field from the documents does work, but there's a noticeable lag before it updates. I've ruled out the possibility of the collection insertion being the source of the lag (simple console.log callback on the client of the first app, logging the id of the newly inserted document).

My purpose for having multiple apps (two to be precise) sharing the same MongoDB is to separate an admin panel from a mobile app without going crazy regarding name-spacing and bloat. This configuration works, but I'm not sure it's the "proper" way of accomplishing the task, and it certainly seems to be causing a performance hit.

Any insight into this matter would be appreciated. Thank you!

EDIT: To clarify, the db URL I'm using is on my localhost, and isn't something hosted online.

Community
  • 1
  • 1
Rashad Nasir
  • 473
  • 3
  • 9

1 Answers1

1

When you use an external database, by default meteor will use periodic polling (every few seconds) in order to observe any changes. The delay you are experiencing is a result of this polling process. You can remove the delay and reduce your app's CPU usage by taking advantage of meteor's oplog tailing feature. In order to use it you will:

  1. Get access to a mongodb instance with the oplog turned on.
  2. Set the environment variable MONGO_OPLOG_URL so your app(s) can read the oplog.

Personally, I'd recommend compose.io for this. They provide exactly this as part of their basic elastic deployment. See this post for detailed instructions.


For users who wish to connect to the oplog created locally for you, you can obtain the URL via:

MongoInternals.defaultRemoteCollectionDriver().mongo._oplogHandle._oplogUrl

It should end up looking something like mongodb://127.0.0.1:3001/local

David Weldon
  • 63,632
  • 11
  • 148
  • 146
  • Hi David, thanks for pointing me in that direction. Compose looks like something I may use when I'm ready for deployment. As for a local configuration - would the MONGO_OPLOG_URL be the same as the MONGO_URL? – Rashad Nasir May 12 '15 at 22:37
  • It's necessarily a different URL. See the update to my answer for what a local version of this should look like. – David Weldon May 12 '15 at 22:43
  • I'm not sure why I couldn't get it working the first time. But I managed to a minute ago. Launched the first meteor instance, **then** modified my bash profile with `export MONGO_URL='mongodb://127.0.0.1:3001/meteor' export MONGO_OPLOG_URL='mongodb://127.0.0.1:3001/local'` and added the `meteor add facts` package to both meteor apps, and finally saw "observe-drivers-oplog" listed under both. Excellent. Thanks a lot David! – Rashad Nasir May 12 '15 at 23:19