Does minimongo compare saves?


#1

Hi everyone,

I am wondering how/if minimongo compares what is saved to what was in de db? I have somewhat large documents (well, 5 KB each) and I update several fields but not all at once. At the moment I just do a {$set : objTest} with basically the whole document. Does it pay to check for differences myself, or is minimongo clever enough to push only changes to the server?
I tried finding some info in the docs on this, but I cannot really find a clear answer.

thanks for any insight,

Paul


#2

Everything in {$set: objTest} will be pushed to the server. A really easy way to verify this is to install the Meteor DevTools Chrome extension. When you’re making your update, watch the DDP tab of this extension; you’ll see everything passed to the server via DDP, which will include everything in your $set object. When it comes to reading things back however, that’s a bit of a different story (since Meteor then leverages its server side cache called mergebox). For the most part only changes are pushed back to the client from the server (there are exceptions since mergebox only works with top level fields). For more info on how mergebox works, see the Subscription lifecycle section of the Guide.


#3

Hi @hwillson,

thank you for this very complete and precise answer! I will implement a
check on which fields have actually changed, then :slight_smile:
I am thinking about a lib like this one :
https://atmospherejs.com/vjau/jsdiff2mongo
That will remedie this problem. I am a bit surprised that minimongo does
not perform this check… I will read the docs you pointed me to to see if
I can find out why.

Thanks!

Paul