MongoDB DEV · Question 69 · Single choice

Consider a collection called cities where the following updateMany is run: db.cities.updateMany( { "name": "Happy Vale", type: "village" }, { $inc: { "pop": 100 } } ) Here is the original document prior to running the updateMany block (above): { "_id": ObjectId("60897a2ed1119ba1a1e1e63d"), "type": "village", "pop": 50, "name": "Happy Vale" } What is the expected resulting document after the update query above ? Choose the best answer:

Answer options

  1. A.
    { "_id": ObjectId("60897a2ed1119ba1a1e1e63d"), "type": "village", "pop": 100, "name": "Happy Vale" }
  2. B.
    { "_id": ObjectId("60897a2ed1119ba1a1e1e63d"), "type": "village", "pop": 150, "name": "Happy Vale" }
  3. C.
    { "_id": ObjectId("60897a2ed1119ba1a1e1e63e"), "type": "town", "pop": 1000, "name": "Sunshine Creek" }

Answer confidence: High

Correct answer: B

Explanation language: Chinese

文档同时满足 name:"Happy Vale" 与 type:"village",$inc 把 pop 从 50 增加 100 得到 150,_id 及其它字段保持不变。A 相当于把 pop 直接写成 100($set 的效果),C 则是另一条完全不同的文档(另一个 _id、另一个城市)。

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 ↗