MongoDB DBA · Question 357 · Multiple choice

Consider a collection called coll which contains only the following documents: { _id: 2, a: [ 3, 7 ] } { _id: 3, a: [ 6, 7 ] } { _id: 5, a: [ 4, 4 ] } The following is the desired update to the document, which of the choices below would generate this update to the document? { _id: 5, a: [ 4, 4, 7 ] } Check all that apply:

Answer options

  1. A.
    db.coll.update( { a: 4 }, { $push: { a: 4 } }
  2. B.
    db.coll.update( { a: 3 }, { $push: { a: 4 } } )
  3. C.
    db.coll.update( { a: 4 }, { $push: { a: 7 } } )

Answer confidence: High

Correct answer: C

Explanation language: Chinese

目标结果 {_id:5, a:[4,4,7]} 只能由 _id:5 的文档(a:[4,4])再 push 一个 7 得到:C 用 {a:4} 定位到该文档后 $push:7,正确。A 命中同一个文档但 push 的是 4,结果是 [4,4,4];B 的 {a:3} 匹配的是 _id:2(a:[3,7]),会把 4 加到错误的文档上。(A 选项缺一个右括号,但不影响判断。)

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 ↗