MongoDB TutorialLesson 9Free preview
MongoDB Delete
This lesson is part of MongoDB · All levels
Summary
This lesson discusses deleting documents with deleteOne() and deleteMany() in mongosh. deleteOne() only deletes the first one document that fits the filter, whereas deleteMany() deletes the entire document that fits, including all collection contents when the filter is empty. The result of deletion is deletedCount showing the number of deleted documents.
Key points
- Delete the first one that fits the filter
- Delete all documents that fit the filter
- Filter is empty on deleteMany deletes the entire collection content
- DeletedCount reports the number of documents that were successfully deleted
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.