deleteOne(filter)removes the first matching document.deleteMany(filter)removes all matches.deleteMany({})empties the collection!db.students.drop()deletes the whole collection.
MongoDB Delete
deleteOne and deleteMany.
✍️ 2 exercises in this lessonKey Takeaways: MongoDB Delete
Mastering MongoDB Delete helps you write clean and reliable MongoDB code. Follow standard conventions, test edge cases, and keep logic simple. Try running the code example below and complete the exercises to build confidence.
MongoDB Delete Code Example
MongoDBdb.students.deleteOne({ name: "Usman" })
db.students.deleteMany({ marks: { $lt: 50 } })
Output
{ acknowledged: true, deletedCount: 1 }
{ acknowledged: true, deletedCount: 0 }
Run this example on your own computer. The "Get Started" lesson shows how to set it up.
MongoDB Delete Practice Exercises
Check what you learned in “MongoDB Delete”.
/ 2 solved
Fill in the blank
Delete every matching document.
db.logs.({ level: "debug" })
✓ Correct!
Not quite. Try again.
Multiple choice
What does db.students.deleteMany({}) do?
✓ Correct!
Not quite. Try again.
to save your exercise progress.
Finished this lesson?
Mark it complete to track your progress.
Stuck on something?
Ask the community in the CodesInTech forum.
Need a developer?
Learning on your own is great — and when you need professional help, our team builds custom software, websites and mobile apps for clients worldwide.
Explore Our Services