nerdexam
MongoDB

C100DBA · Question #5

Which option should be used to update all the documents with the specified condition in the MongoDB query?

The correct answer is D. specify {multi : true} as the third parameter of update command. In MongoDB's update() command, passing {multi: true} as the third parameter (the options object) instructs the engine to apply the update to all documents matching the query filter, rather than stopping after the first match - making D correct. Option A is wrong because {all: tru

MongoDB Fundamentals

Question

Which option should be used to update all the documents with the specified condition in the MongoDB query?

Options

  • Aspecify {all: true} as the third parameter of update command
  • BupdateAII instead of update
  • Cspecify {updateAII: true} as the third parameter of update command
  • Dspecify {multi : true} as the third parameter of update command

How the community answered

(31 responses)
  • A
    6% (2)
  • C
    3% (1)
  • D
    90% (28)

Explanation

In MongoDB's update() command, passing {multi: true} as the third parameter (the options object) instructs the engine to apply the update to all documents matching the query filter, rather than stopping after the first match - making D correct. Option A is wrong because {all: true} is not a valid MongoDB option and will be silently ignored. Option B is wrong because updateAll does not exist as a MongoDB method (the modern equivalent is updateMany(), not updateAll). Option C is wrong because {updateAll: true} is also not a recognized option in the update command.

Memory tip: Think of multi as "multiple documents" - set {multi: true} to update multiple, leave it out (default false) to update only one. If you remember the modern API, updateMany() is the {multi: true} equivalent, which can help you anchor the concept.

Topics

#multi update#update operations#write operations#bulk update

Community Discussion

No community discussion yet for this question.

Full C100DBA Practice