Eugene Goldberg
Eugene Goldberg

Reputation: 15544

why is meteor Tracker.autorun() detects mongodb changes with a delay, if the collection was modified outside of the meteor application

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?

Upvotes: 1

Views: 253

Answers (1)

Eugene Goldberg
Eugene Goldberg

Reputation: 15544

Once I have this question posted on meteor forums, I was pointed to a meteor blog post from 2014, which describes the oplog tailing feature, and the fact, that it is only on by default in the dev instance. This made me realize, that, by using MONGO_URL env variable with my dev application, I was forcing my meteor app to work with the MongoDB instance, which was running on my mac all the time, independently from my meteor development, and, as such, was considered as "production" by my meteor app. Once I have switched the app to work with ad-hock mongo connection / db, the oplog tailing went into effect, and I started to see immediate event propagation to the browser. Thanks, @dburles from the meteor forums!

Upvotes: 1

Related Questions