Deletes a single record and returns the deleted record.
Method definition
findOneAndDelete(filter: object, options?: object): Promise<MongoResult>Request parameters
Field name | Type | Required | Description |
|---|---|---|---|
| Object | Yes | The query criteria for the operation. |
| Object | No | Control. |
options parameter is defined as follows:Field name | Type | Required | Description |
|---|---|---|---|
| Object | No | Specifies the fields to sort by. Use
|
| Object | No | Specifies the fields to return. A value of 1 includes the field. A value of 0 excludes it. The |
| Number | No | The running time in milliseconds. Default: 1000. Maximum: 3000. |
Examples
Find and delete a record from the
userscollection where theagefield is 18, and then return the deleted record. If multiple records match, the first matching record is deleted and returned.mpserverless.db.collection('users').findOneAndDelete({ age: 18, }) .then(res => {}) .catch(console.error)Find a record in the
userscollection where theagefield is 18. If multiple records match, the one that is first in ascending order bynameis selected. The selected record is then deleted, and itsnamefield is returned.mpserverless.db.collection('users').findOneAndDelete({ age: 18, }, { projection: { _id: 0, name: 1 }, sort: { name: 1 }, }) .then(res => {}) .catch(console.error);