MongoDB DBA · Question 11 · Multiple choice

11. Consider a collection called travel with the following index: { "name": 1,"age": -1,"visited": 1 } Which of the following queries can use this index? Check all that apply:

Answer options

  1. A.
    db.travel.find( { "visited.0": "Ireland"} )
  2. B.
    db.travel.find( { "age": { "$lt": 10} } ).sort( { "name": 1 } )
  3. C.
    db.travel.find( { } ).sort( { "name": 1 } )
  4. D.
    db.travel.find( { "age": { "$lt": 40 }, "visited": "Monaco" } )
  5. E.
    db.travel.find( { "visited": "Ireland", "name": "Lillian Hernandez" } )

Answer confidence: Medium

Correct answer: B, C, E

Explanation language: Chinese

B、C 都是靠索引提供排序:索引首字段是 name,查询虽然过滤 age,但 sort({name:1}) 是索引前缀,MongoDB 会做整索引扫描(IXSCAN)后 FETCH 再过滤 age,从而避免内存排序。E 对首字段 name 的等值条件足以使用索引(visited 作为残余过滤),所以也可用。A 错在 "visited.0" 是数组位置子路径,而索引建在 visited 整体上、键是元素值,两者对不上;D 跳过了首字段 name,age/visited 都落在非前缀位置,构不成有界索引扫描。

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 ↗