nerdexam
MongoDB

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

MongoDB Fundamentals

Question

You perform the following query; How many documents will be updated by the query?

Exhibit

C100DBA question #118 exhibit

Options

  • A0
  • B1
  • C2
  • D3
  • E5

How the community answered

(37 responses)
  • A
    3% (1)
  • B
    89% (33)
  • D
    5% (2)
  • E
    3% (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

#update#single document update#write operations

Community Discussion

No community discussion yet for this question.

Full C100DBA Practice