A. deleteMany cannot delete documents by category.
B. The collection name is incorrect.
C. Missing semicolon at the end.
D. Filter should be an object, not a string.
Solution
Step 1: Check filter argument type
The filter argument must be a JSON object, but here it is passed as a string.
Step 2: Validate other parts
deleteMany can delete by any filter, semicolon is optional in JS, and collection name is valid.
Final Answer:
Filter should be an object, not a string. -> Option D
Quick Check:
Filter must be object, not string = B [OK]
Hint: Pass filter as object, not string, in deleteMany [OK]
Common Mistakes:
Passing filter as string instead of object
Assuming semicolon is mandatory
Misnaming collection
5. You want to delete all documents from the orders collection where the status is either "cancelled" or "returned". Which deleteMany filter correctly achieves this?
hard
A. db.orders.deleteMany({status: "cancelled" || "returned"})
B. db.orders.deleteMany({status: {$in: ["cancelled", "returned"]}})
C. db.orders.deleteMany({status: {$or: ["cancelled", "returned"]}})
D. db.orders.deleteMany({status: ["cancelled", "returned"]})
Solution
Step 1: Understand filter for multiple values
To match documents where a field equals any value in a list, MongoDB uses the $in operator with an array of values.
Step 2: Evaluate each option
db.orders.deleteMany({status: {$in: ["cancelled", "returned"]}}) correctly uses $in. db.orders.deleteMany({status: "cancelled" || "returned"}) uses JavaScript OR incorrectly inside an object. db.orders.deleteMany({status: {$or: ["cancelled", "returned"]}}) misuses $or inside a field. db.orders.deleteMany({status: ["cancelled", "returned"]}) uses an array directly, which is invalid.
Final Answer:
db.orders.deleteMany({status: {$in: ["cancelled", "returned"]}}) -> Option B
Quick Check:
Use $in for multiple values in filter = C [OK]
Hint: Use $in operator to match multiple values in deleteMany filter [OK]