findOneAndDelete() (Delete and Return a Document)
Last updated: 2026-10-09
findOneAndDelete() (Delete and Return a Document)
findOneAndDelete() removes the first document matching a filter and returns the removed document itself, e.g. `db.users.findOneAndDelete({ name: 'Cara' })`. Unlike deleteOne(), which returns only counters, it hands back the full document — useful for archiving or auditing deletions. It returns null when nothing matches.
| Category | Write |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
db.<collection>.findOneAndDelete(<filter>, { projection: <fields> })
⚙️ Parameters
| filter | Predicate matching the document to delete. |
|---|---|
| projection | Optional. Controls which fields of the deleted document are returned. |
Returns:The deleted document; null when nothing matches.
▶ Example
Run the commands below in your local mongosh (requires a running mongod):
// findOneAndDelete: remove Cara and print her record
const removed = db.users.findOneAndDelete({ name: 'Cara' })
removed
Output:
{
_id: ObjectId('64c8a1b20000000000000003'),
name: 'Cara',
age: 30
}
📌 Notes
- Returns the removed document for archiving or auditing
- Deletes only the first match
- Returns null instead of throwing when nothing matches
🏷️ Related Tags
💡 Related Cases
📚 Related Tutorials
❓ FAQ
QWhat is the difference between findOneAndDelete and deleteOne?
AdeleteOne() returns deletedCount only; findOneAndDelete() returns the full deleted document for archiving and audit.
QWhat does findOneAndDelete return when nothing matches?
AIt returns null without throwing, letting you tell whether the filter matched.
QCan findOneAndDelete limit the returned fields?
AYes, via the projection option — e.g. {projection: {name: 1}} returns only the name.