A. The filter syntax is incorrect and causes a syntax error.
B. MongoDB does not support upsert with updateOne.
C. The update document is missing the $set operator.
D. Missing the upsert: true option in the updateOne call.
Solution
Step 1: Check the updateOne parameters
The updateOne call lacks the options object with upsert: true, so it only updates existing documents.
Step 2: Confirm upsert behavior
Without upsert: true, no new document is inserted if the filter finds no match.
Final Answer:
Missing the upsert: true option in the updateOne call. -> Option D
Quick Check:
Upsert option needed to insert new docs [OK]
Hint: Add {upsert: true} to updateOne options to insert [OK]
Common Mistakes:
Forgetting to add upsert option
Confusing missing $set with upsert behavior
Believing updateOne cannot upsert
5. You want to update the status field to "active" for a user with email: "user@example.com". If no such user exists, insert a new document with email and status. Which MongoDB command correctly achieves this?