Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Meteor batch update

Tags:

mongodb

meteor

I'm using meteor. I'm wondering if theres a shorthand way to do batch updates before the DOM is updated.

for instance I want to update some records,more than one (All at once):

Collection.update(id1,{..})
Collection.update(id2,{..})
Collection.update(id3,{..})

The problem is there are 3 items being updated separately. So when the DOM in my case was being redrawn 3 times instead of once (with all 3 updated records).

Is there a way to hold off the ui updating until all of them are updated?

like image 858
Tarang Avatar asked Jun 18 '12 15:06

Tarang


People also ask

What version is meteor?

The Meteor PvP server is a 1.16 style combat server that features anchor, bed, and crystal PvP styles accessible to players on versions 1.14 and newer. This server also features a custom kit and duel plugin.

What is Meteor collection?

Collections are Meteor's way of storing persistent data. The special thing about collections in Meteor is that they can be accessed from both the server and the client, making it easy to write view logic without having to write a lot of server code.


1 Answers

Mongo's update can modify more than one document at a time. Just give it a selector that matches more than one document, and set the multi option. In your case, that's just a list of IDs, but you can use any selector.

Collection.update({_id: {$in: [id1, id2, id3]}}, {...}, {multi:true});

This will run a single DB update and a single redraw.

like image 141
debergalis Avatar answered Oct 23 '22 13:10

debergalis