Lesson 11 / 22
deleteOne & deleteMany
Remove documents that match a filter.
deleteOne()
Removes the first document matching the filter.
db.users.deleteOne({ name: "Alan Turing" })
Output:
{ acknowledged: true, deletedCount: 1 }deleteMany()
Removes every document matching the filter.
db.users.deleteMany({ role: "intern" })
Output:
{ acknowledged: true, deletedCount: 3 }Careful with an empty filter
deleteMany({}) removes every document in the collection — always double-check the filter before running it.