1

Let's say I have a query like

Users.find().sort({score: 1}).limit(3) which I publish on the server.

So, I have some code like this:

Meteor.publish("leaders", function () {
   return Users.find().sort({score: 1}).limit(3)
});

Now, let's say, there is some change (insert/update/delete) in the Users collection.

Are all the queries on that collection run again? or does Meteor run only certain queries whose results might actually change due to database change?

For example, a query that returns first three users Users.find().limit(3) will return the same value even after new inserts, so re-running it will not have any effect.

Edit: I know that Meteor tails the Mongo oplog and propagates those changes to the clients, so I am not looking for an explanation on how it does realtime. More on the lines of, how(or whether) it tracks which queries are affected by a change.

Jatin
  • 14,112
  • 16
  • 49
  • 78
  • A good answer to this question requires in-depth explanations of Mongo Oplog, the Meteor's Mongo driver, reactivity, the `Mongo.Collection` wrapper... I am afraid it is too broad. – Kyll Sep 13 '15 at 11:09
  • Yeah, it's far too broad to be answered here... – AStopher Sep 13 '15 at 11:10
  • Agreed. Way too broad. – SirCharlesWatson Sep 13 '15 at 12:13
  • @Kyll I have reduced the scope of question. Hopefully that helps. – Jatin Sep 13 '15 at 13:26
  • @Jatin It does, however I am unsure as to how to actually answer. I guess how the tracking is done can be seen in Meteor's github repository, but I am too unfamiliar with the Mongo driver to provide an answer. – Kyll Sep 13 '15 at 13:48

0 Answers0