MongoDB DBA · Question 437 · Multiple choice

12. When an index is created on the "name" field in the "friends" collection, which operation(s) will become more efficient as a result? Check all that apply:

Answer options

  1. A.
    db.friends.insert({"name": "John", "age": 12})
  2. B.
    db.friends.updateOne({"name": "Karen"}, {"$set": {"age":15}})
  3. C.
    db.friends.find({"name": "Emily"})

Answer confidence: High

Correct answer: B, C

Explanation language: Chinese

在 name 上建索引后,任何带 name 条件的操作都能先用索引定位目标文档:C 的 find({"name":"Emily"}) 直接走索引;B 的 updateOne 也先用 {name:"Karen"} 定位再修改,因此都比全集合扫描更高效。A 是插入操作,每插一条都要额外维护 name 索引,插入反而变慢(而且它没有 name 条件可用索引查找),所以不选。

Papers containing this question

This question appears in 1 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 ↗