C100DBA · Question #118
You perform the following query; How many documents will be updated by the query?
The correct answer is B. 1. The query (most likely a MongoDB update() or updateOne() call) only updates 1 document by default, regardless of how many documents match the filter - this is MongoDB's default behavior. Option A (0) is wrong because at least one document matches the query condition, so an update
Question
You perform the following query; How many documents will be updated by the query?
Exhibit
Options
- A0
- B1
- C2
- D3
- E5
How the community answered
(37 responses)- A3% (1)
- B89% (33)
- D5% (2)
- E3% (1)
Explanation
The query (most likely a MongoDB update() or updateOne() call) only updates 1 document by default, regardless of how many documents match the filter - this is MongoDB's default behavior. Option A (0) is wrong because at least one document matches the query condition, so an update does occur. Options C, D, and E (2, 3, or 5) are wrong because without the multi: true option or using updateMany(), MongoDB stops after modifying the first matching document even when more could qualify.
Memory tip: Think of MongoDB's default update() as "update one and done" - it finds the first match and stops. To update all matches, you must explicitly opt in with {multi: true} or switch to updateMany().
Topics
Community Discussion
No community discussion yet for this question.
