Retrieve all document ids modified from collection.update


Anyone knows a way to get all documents ids updated during a ‘collection.update’ with the multi: true ?
Right now, (following what the doc says) it’s only sending back the number of document modified during the query which isn’t useful for what i need.

Do i have to do some ‘collection.find’ in order to get those ?

Thanks !


I am afraid so.

Notice that sometimes you might be able to optimize your update with the result of the find (depending on your query and indexes). Something like this:

  var ids = MyCollection.find({ complex query }).map(function(e) { return e._id; });
  MyCollection.update({ _id: { $in: ids } }, { $set: whatever });
  // Now use the ids ...


Ok :wink:

Kinda weird that nothing like this has been implemented in mongoDB. Can’t be the only one who would need something like that…

Anyway, thanks a lot.