Mongo documentation

Find a document and update it in one atomic operation, requires a write lock for the duration of the operation.


  1. query (String|ObjectId|Object)

  2. update (Object): Update operations to be performed on the document. As written in MongoDB docs, you need to specify an atomic operator here (like a $set, $unset, or $rename).

  3. [options] (Object|String|Array): If the options is a string, it will be parsed as the fields to select.

options.returnOriginal is default to false, while mongodb set it to true for undefined.

  1. [callback] (function)


A promise.


users.findOneAndUpdate({name: 'foo'}, { $set: { name: 'bar'} }).then((updatedDoc) => {})

Note that you can also use the monk-middleware-wrap-non-dollar-update middleware, which will automatically put the $set operator on the update argument:


users.findOneAndUpdate({name: 'foo'}, { name: 'bar'}).then((updatedDoc) => {})

results matching ""

    No results matching ""