Mongoose: findAndModify - atomically find and update multiple documents

Created on 29 Sep 2015  路  2Comments  路  Source: Automattic/mongoose

Why do we still have to manually hack in a way to atomically find and update multiple documents? http://stackoverflow.com/questions/7334390/has-mongoose-support-findandmodify-mongodb-method

(here's the relevant code)

Counters.statics.findAndModify = function (query, sort, doc, options, callback) {
  return this.collection.findAndModify(query, sort, doc, options, callback);
};

All 2 comments

why is this closed, or what is the recommended way to update multiple documents at once and get the list of matched docs (or at least their _ids)? Is it still by using Model#collection.findAndModify(...)?

@huafu not possible with findAndModify: https://docs.mongodb.com/manual/reference/method/db.collection.findAndModify/ . You'd need to do updateMany(), that gives you back the list of ids.

Was this page helpful?
0 / 5 - 0 ratings