Meteor 1.6.1.1
uname -a
Darwin mac.local 16.7.0 Darwin Kernel Version 16.7.0: Mon Nov 13 21:56:25 PST 2017; root:xnu-3789.72.11~1/RELEASE_X86_64 x86_64
situation
I may not be clear about how meteor’s pub/sub works, but here is how I understand it.
server publishes a cursor on a collection
client side subscribe to the publish
client gets the published data up to date
so if your publish is something like this, you get all products that are only on sale in your client side mini-mongo database.
When I get the data, however, what I am experiencing for this case above, I get all products, either onSale true OR false, at the line const productsOnSale = Products.find().fetch() in the client side code.
Is there anything I am missing to get correct filtered data from the publish?
This is normal behaviour for Meteor’s pub/sub. The client gets a merged set of all currently active publications. The way to mitigate this is to repeat the publication’s selection criteria in the find on the client.
Note also, that even if subscriptions are stopped and replaced by subscriptions with different selection criteria, there will be an overlap time when old and new documents are present on the client.
So, long story short, it’s always best to duplicate the server query/queries on the client.