| |
read source history
findOneAndDelete()
MongoDB Driver Function Reference
Deletes a single document based on the filter and sort criteria, returning the deleted document.
More information can be found in the corresponding entry of the MongoDB Manual.
<collection>.findOneAndDelete(<filter>[, <options>])
|
Arguments
<collection> | | The target collection. |
<filter> | | A filter expression using query operators. |
<options> | | A BOSN document specifying options. |
|
Options
{ projection: <document>, sort: <document>, maxtime: <long>, collation: <document>, hint: <document> }
projection | | Defines a subset of fields to return. |
sort | | Specifies a sort order. |
maxtime | | Specifies a time limit in milliseconds. |
collation | | A document specifying the collation. |
hint | | A document specifying a hint. |
|
Example
db.employees.findOneAndDelete({ salary: { $gt: 700000 }}, { sort: { age: 1 }});
|
Finds document from the employee collection with a salary greater than 700000, sorts them by age, then deletes the first document in the result.
home | MongoDB Driver Function Reference | MongoDB Driver
|