Query.prototype.findOneAndRemove()

Parameters
  • [conditions] «Object»
  • [options] «Object»

  • [options.rawResult] «Boolean» if true, returns the raw result from the MongoDB driver

  • [options.session=null] «ClientSession» The session associated with this query. See transactions docs.

  • [options.strict] «Boolean|String» overwrites the schema’s strict mode option

  • [callback] «Function» optional params are (error, document)

Returns:
  • «Query» this

Issues a mongodb findAndModify remove command.

Finds a matching document, removes it, passing the found document (if any) to the callback. Executes if callback is passed.

This function triggers the following middleware.

  • findOneAndRemove()

Available options

  • sort: if multiple docs are found by the conditions, sets the sort order to choose which doc to update
  • maxTimeMS: puts a time limit on the query - requires mongodb >= 2.6.0
  • rawResult: if true, resolves to the raw result from the MongoDB driver

Callback Signature

  1. function(error, doc) {
  2. // error: any errors that occurred
  3. // doc: the document before updates are applied if `new: false`, or after updates if `new = true`
  4. }

Examples

  1. A.where().findOneAndRemove(conditions, options, callback) // executes
  2. A.where().findOneAndRemove(conditions, options) // return Query
  3. A.where().findOneAndRemove(conditions, callback) // executes
  4. A.where().findOneAndRemove(conditions) // returns Query
  5. A.where().findOneAndRemove(callback) // executes
  6. A.where().findOneAndRemove() // returns Query