MongoDB DEV · Question 62 · Multiple choice

Consider the following update command: var updateDocument = ... db.books.updateOne({ "title": "Catch-22" }, updateDocument) Select which value for updateDocument will add multiple individual review sub-documents to the reviews array field: Check all that apply:

Answer options

  1. A.
    { "$push": { "reviews": [ { "rating": 1, "text": "review 1" }, { "rating": 2, "text": "review 2" } ] } }
  2. B.
    { "$inc": { "reviews": { "$each": [ { "rating": 1, "text": "review 1" }, { "rating": 2, "text": "review 2" } ] } } }
  3. C.
    { "$push": { "reviews": { "$each": [ { "rating": 1, "text": "review 1" }, { "rating": 2, "text": "review 2" } ] } } }

Answer confidence: High

Correct answer: C

Explanation language: Chinese

要向数组字段一次追加"多个独立子文档",必须用 $push 搭配 $each:$each 会把数组中的每个元素逐个 push 进去(C)。A 直接把数组字面量交给 $push,会把整个数组当成一个嵌套数组元素插入;B 的 $inc 是数值自增操作符,不接受 $each,语法本身无效。

Papers containing this question

This question appears in 3 bank records. Public pages combine identical prompts and options. Selected questions display the highest-confidence record; the others show a short preview. Paper-based learning preserves each record's answer, explanation, and confidence.

AUTHOR · PROJECTS · OPEN SOURCE

Author & MongoDB projects

Building data platforms, MongoDB migration and sync tools, and cloud operations products.

Contact the author for any MongoDB needs.

Contact the author ↗mlhp123@outlook.com

Support the author

If this question bank helps you, optional donations are welcome.

Scan with Alipay to support the authorOpen full-size donation image ↗