Model.findByIdAndRemove()
Parameters
id «Object|Number|String» value of
_id
to query by[options] «Object» optional see
Query.prototype.setOptions()
[options.strict] «Boolean|String» overwrites the schema’s strict mode option
[options.session=null] «ClientSession» The session associated with this query. See transactions docs.
[options.projection=null] «Object|String|Array<String>» optional fields to return, see
Query.prototype.select()
[callback] «Function»
Returns:
- «Query»
Issue a mongodb findAndModify remove command by a document’s _id field. findByIdAndRemove(id, ...)
is equivalent to findOneAndRemove({ _id: id }, ...)
.
Finds a matching document, removes it, passing the found document (if any) to the callback.
Executes the query if callback
is passed.
This function triggers the following middleware.
findOneAndRemove()
Options:
sort
: if multiple docs are found by the conditions, sets the sort order to choose which doc to updateselect
: sets the document fields to returnrawResult
: if true, returns the raw result from the MongoDB driverstrict
: overwrites the schema’s strict mode option for this update
Examples:
A.findByIdAndRemove(id, options, callback) // executes
A.findByIdAndRemove(id, options) // return Query
A.findByIdAndRemove(id, callback) // executes
A.findByIdAndRemove(id) // returns Query
A.findByIdAndRemove() // returns Query