MongoDB provides methods to delete documents from collections based on filters. The most common methods are deleteOne()
and deleteMany()
.
Deletes the first document that matches the given filter.
db.users.deleteOne({ name: "John" })
Deletes all documents that match the given filter.
db.users.deleteMany({ status: "inactive" })
This will delete every document in a collection.
db.users.deleteMany({})
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!