Consider the following index in the buildings collection: { height: 1 } Which of the following queries could use this index? Check all that apply:
题目选项
- A.db.buildings.find({ year: { $lte: 1980 } })
- B.db.buildings.find({ height: { $gt: 50 } })
- C.db.buildings.find({ height: 100, city: "London" })
答案置信度:高
正确答案:B、C
解析语言:中文
单字段索引 {height:1} 只能服务带 height 条件的查询:A 是 height 的范围查询,C 是 height 等值过滤后再用 city 做残余过滤,两种都能先用索引缩小候选文档。B 只查 year,索引中根本没有该字段,只能全集合扫描。C 里 city 没有索引并不妨碍使用 height 索引,只是过滤要回表后再判断。