Why is there a delay in Tracker.autorun() detecting mongodb changes when changes are made outside of the app

A very simply scenario: in a local meteor (v 1.2.1) development environment (WebStorm), with autopublish, and insecure enabled, I have a single MongodbDB (v 3.0.4) collection ‘Letters’. I wish to respond immediately to any documents being added, removed, or modified in this collection.

For this purpose, I have the following autorun function:

Template.diagram.rendered = function(){

Tracker.autorun(function () {
Letters.find({}).observe({
added: function(document) {
console.log(‘a new document has been added’);
},
changed: function(newDocument) {
console.log(‘a document has been changed’);
},
removed: function(document) {
console.log(‘a document has been removed’);
}
});
})
}

When a new document is added from within the same application, I can see the console messages right away (meteor latency compensation). However, when I connect to the same MongoDB database using an external tool (Robomongo), and add, change, or remove a document within the ‘Letters’ collection - it takes about 6-10 seconds before this change is detected, and the corresponding console message appears in the browser. Why does it take this long, instead of being almost instantaneous?

Hey @goldberg unless Meteor is configured to make use of the MongoDB oplog, it will poll the database for changes rather than reacting to them immediately. Take a look here: https://github.com/meteor/meteor/wiki/Oplog-Observe-Driver

Hey @dburles
Thank you for pointing me to this blog
Its says, that in development environments, which mine is, the oplog tailing is automatically enabled.
In my WebStorm’s terminal window, I put “meteor run” to start my app, but it still has about 7 second delay, which, as you have explained, is due to meteor polling, and not using oplog tailing.
Is there a specific command, or a configuration parameter, which will force meteor to use oplog tailing?

Hey @dburles
I think, I understand now where my problem is: I had my meteor app connected to a MondgoDB instance, which runs on my mac all the time, regardless my meteor development, and, therefore, would be considered “production” from my app’s stand point, which would require additional steps to enable the oplog trailing, as per the blog.
Once I have switched my app to use that ad-hock mongo connection, the oplog tailing went into effect, and all changes were propagating to the browser right away.
Thanks again!

Great! yeah, since you mentioned Mongo 3, I figured that’s what you’re likely doing :slightly_smiling: