deleteOne() (Delete a Single Document)

Last updated: 2026-10-09

deleteOne() (Delete a Single Document)

deleteOne() removes the first document matching a filter; if several match, only the first in natural order is deleted. The result includes deletedCount (0 or 1). Deletions cannot be undone, so it is wise to confirm the target with `db.users.findOne({ name: 'Alice' })` first. It is the most direct way to remove a single document.

CategoryWrite
MongoDB Version1.0+
Example Languagemongosh (Shell)

📝 Syntax

db.<collection>.deleteOne(<filter>, { writeConcern: <options> })

⚙️ Parameters

filterPredicate matching the document to delete.
writeConcernOptional. Write concern.

Returns:DeleteResult: { acknowledged, deletedCount }.

▶ Example

Run the commands below in your local mongosh (requires a running mongod):

// deleteOne: delete the user named Alice
db.users.deleteOne({ name: 'Alice' })

Output:

{ acknowledged: true, deletedCount: 1 }

📌 Notes

📚 Related Tutorials

❓ FAQ

QDoes deleteOne delete all matching documents?
ANo, deleteOne() removes only the first match. Use deleteMany() to remove every match.
QDoes deleteOne throw when nothing matches?
ANo error — it returns deletedCount: 0, which tells you whether the filter matched anything.
QCan a deleted document be recovered?
ANot via the API. Deletion is physical; recovery depends on backups or oplog (replica sets), so back up important data first.
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%

🙏 帮我们做得更好

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

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