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.
| Category | Write |
|---|---|
| MongoDB Version | 1.0+ |
| Example Language | mongosh (Shell) |
📝 Syntax
db.<collection>.deleteOne(<filter>, { writeConcern: <options> })
⚙️ Parameters
| filter | Predicate matching the document to delete. |
|---|---|
| writeConcern | Optional. 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
- Deletes only the first match; use deleteMany() to delete all
- deletedCount of 0 means no match — not an error
- Deletion is irreversible; look before you delete in production
🏷️ Related Tags
💡 Related Cases
📚 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.