Recall & Review
beginner
What does the
deleteMany() method do in MongoDB?It removes all documents from a collection that match a given filter condition.
Click to reveal answer
beginner
How do you specify which documents to delete using
deleteMany()?You provide a filter object that describes the criteria documents must meet to be deleted.
Click to reveal answer
intermediate
What does
deleteMany({}) do?It deletes all documents in the collection because the empty filter matches everything.
Click to reveal answer
intermediate
What is the return value of
deleteMany()?It returns a result object containing the number of documents deleted, accessible via
deletedCount.Click to reveal answer
beginner
Why should you be careful when using
deleteMany() without a filter?Because it will delete all documents in the collection, which might cause data loss if unintended.
Click to reveal answer
What does
deleteMany({ age: { $lt: 18 } }) do?✗ Incorrect
The filter { age: { $lt: 18 } } matches documents with age less than 18, so those are deleted.
What will happen if you call
deleteMany({}) on a collection?✗ Incorrect
An empty filter matches all documents, so all documents are deleted.
Which property tells you how many documents were deleted after
deleteMany()?✗ Incorrect
The result object from deleteMany() includes a property called deletedCount showing how many documents were removed.
If you want to delete documents where the field 'status' equals 'inactive', what filter should you use?
✗ Incorrect
The filter { status: 'inactive' } matches documents where status is exactly 'inactive'.
Is it possible to delete documents using
deleteMany() without specifying a filter?✗ Incorrect
Calling deleteMany() with an empty filter deletes all documents in the collection.
Explain how the
deleteMany() method works in MongoDB and what happens if you use an empty filter.Think about how you tell MongoDB which documents to remove.
You got /3 concepts.
Describe the importance of the
deletedCount property after calling deleteMany().Consider how you know if your delete worked.
You got /3 concepts.