Query.prototype.findOneAndDelete()
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 findOneAndDelete command.
Finds a matching document, removes it, and passes the found document (if any) to the callback. Executes if callback
is passed.
This function triggers the following middleware.
findOneAndDelete()
This function differs slightly from Model.findOneAndRemove()
in that findOneAndRemove()
becomes a MongoDB findAndModify()
command, as opposed to a findOneAndDelete()
command. For most mongoose use cases, this distinction is purely pedantic. You should use findOneAndDelete()
unless you have a good reason not to.
Available options
sort
: if multiple docs are found by the conditions, sets the sort order to choose which doc to updatemaxTimeMS
: puts a time limit on the query - requires mongodb >= 2.6.0rawResult
: if true, resolves to the raw result from the MongoDB driver
Callback Signature
function(error, doc) {
// error: any errors that occurred
// doc: the document before updates are applied if `new: false`, or after updates if `new = true`
}
Examples
A.where().findOneAndDelete(conditions, options, callback) // executes
A.where().findOneAndDelete(conditions, options) // return Query
A.where().findOneAndDelete(conditions, callback) // executes
A.where().findOneAndDelete(conditions) // returns Query
A.where().findOneAndDelete(callback) // executes
A.where().findOneAndDelete() // returns Query