16. Given the following query: db.clothes.find( { "price": { "$lt": 50.00 }, "category": "dress shirt" } ).sort( { "stars": -1 } ) Which index on the clothes collection will be the most performant for the above query? Choose the best answer:
题目选项
- A.{"stars": 1, "price": 1, "category": 1}
- B.{"stars": 1, "category": 1, "price": 1}
- C.{"category": 1, "stars": 1, "price": 1}
- D.{"category": 1, "price": 1, "stars": 1}
- E.{"price": 1, "stars": 1, "category": 1}
答案置信度:高
正确答案:C
解析语言:中文
按 ESR 规则(Equality 等值 → Sort 排序 → Range 范围)排列字段:等值条件 category 放最前,排序字段 stars 放第二,范围条件 price 放最后,即 {category: 1, stars: 1, price: 1}(E)。A 把范围字段 price 放在排序字段之前,索引无法继续提供排序;C、D 以 stars 打头、把等值条件放到后面,过滤效率差;B 以范围字段打头同样无法支持按 stars 排序。