MongoDB DBA · Question 370 · Multiple choice

Consider the following index in the buildings collection: { height: 1 } Which of the following queries could use this index? Check all that apply:

Answer options

  1. A.
    db.buildings.find({ year: { $lte: 1980 } })
  2. B.
    db.buildings.find({ height: { $gt: 50 } })
  3. C.
    db.buildings.find({ height: 100, city: "London" })

Answer confidence: High

Correct answer: B, C

Explanation language: Chinese

单字段索引 {height:1} 只能服务带 height 条件的查询:A 是 height 的范围查询,C 是 height 等值过滤后再用 city 做残余过滤,两种都能先用索引缩小候选文档。B 只查 year,索引中根本没有该字段,只能全集合扫描。C 里 city 没有索引并不妨碍使用 height 索引,只是过滤要回表后再判断。

Papers containing this question

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