findOneAndDelete
findOneAndDelete is a MongoDB operation that finds a single document matching a given filter and deletes it. It returns the deleted document as the operation’s value, or null if no document matched. The command selects which document to delete using an optional sort specification when multiple matches exist, and it deletes only one document.
In the MongoDB shell, the form is: db.collection.findOneAndDelete(filter, options). In drivers such as the Node.js driver,
The command result includes value, which is the deleted document, or null if no matching document was
findOneAndDelete uses the server’s findAndModify mechanism to remove a single document. It is suitable when you
findOneAndDelete is available in modern MongoDB deployments and supported by official drivers and the shell. It