deleteOne() — MongoDB Technical Interview Questions & Answers
Deletes the first document matching a filter.
deleteOne()
- Simple meaning: deleteOne removes the first matching document.
- How to use: db.students.deleteOne({ roll: 12 }).
- Result: deletedCount 0 or 1.
- Try this: insert, deleteOne, findOne — should be null.
- Common mistake: deleteMany({ city: "Pune" }) when you meant one student.
- Interview tip: First match only. Unique filter (roll/_id).
Technical Interview Tip: deleteOne with a unique field.
Code Examples for deleteOne()
deleteOne() — working example
db.users.deleteOne({ email: "ada@example.com" })deleteOne() — deleteOne removes at most one matching document (the first match).
How to Explain deleteOne() to an Interviewer
How do you delete one student?
deleteOne({ roll: 12 })