Sync mini-mongo with method results

Hi,

what you are using to calculate what need to be inserted/updated/removed to client side only mongo collection based on method result call?
I am using low level publish atm, but I would like to offload this to client itself and still minimize the Blaze DOM manipulations, so not replacing whole set of results, but using standard insert/update/remove.

And I am kinda lazy to prepare and debug these few underscore/lodash helpers myself if other people already did it according to talks here.

I remember @SkinnyGeek1010 is using methods to feed them.

User_local = new Mongo.Collection('user_local', {connection: null});

Meteor.call('getUser', 'id123', function(err, res) {
  if(!err) User_local.upsert(res);
});
2 Likes

Ok, that would cover the added and changed.

For remove if we are talking about returning array of documents, u are using something like this?

currentIds = User_local.find().map(function(user) {return user._id})
resultIds = res.map(function(user) {return user._id})

_.each(_.without(currentIds, resultIds), function (userId) {User_local.remove({ _id: userId})})

yea i think that would be fine