I\'ve a collection of data and I need to add for every documents a new field. If I run a query to get all documents and the update every single one node.js is stopped, may be fo
You can drop down to the collection level and do a bulk update. This action will not be atomic - some of the writes can fail and others might succeed - but it will allow you to make these writes in a single round trip to your database.
It looks like this:
var bulk = People.collection.initializeUnorderedBulkOp();
bulk.find({}).update({});
bulk.find({}).update({});
...
bulk.execute(function(err) {
...
});
Check out the docs here: http://docs.mongodb.org/manual/core/bulk-write-operations/