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.

CategoryWrite
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

db.<collection>.findOneAndDelete(<filter>, { projection: <fields> })

⚙️ Parameters

filterPredicate matching the document to delete.
projectionOptional. 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

📚 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.
Web-Tutorial.com

Web-Tutorial Tech Team

A team of developers maintaining programming tutorials. Each tutorial is written and reviewed by developers with expertise in that field. We work to keep our content accurate and reliable — if you spot an issue, please let us know.

100%

🙏 帮我们做得更好

我们是刚上线的编程教程站,几个人的小团队,精力有限。页面虽经检查,难免还有疏漏——链接失效、排版错乱、内容有误、语言生硬……

如果您发现了,麻烦告诉我们,我们会在收到反馈后第一时间进行修复,再次感谢您的光临 🙏