MongoDB DBA · Question 238 · Single choice

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:

Answer options

  1. A.
    {"stars": 1, "price": 1, "category": 1}
  2. B.
    {"stars": 1, "category": 1, "price": 1}
  3. C.
    {"category": 1, "stars": 1, "price": 1}
  4. D.
    {"category": 1, "price": 1, "stars": 1}
  5. E.
    {"price": 1, "stars": 1, "category": 1}

Answer confidence: High

Correct answer: C

Explanation language: Chinese

按 ESR 规则(Equality 等值 → Sort 排序 → Range 范围)排列字段:等值条件 category 放最前,排序字段 stars 放第二,范围条件 price 放最后,即 {category: 1, stars: 1, price: 1}(E)。A 把范围字段 price 放在排序字段之前,索引无法继续提供排序;C、D 以 stars 打头、把等值条件放到后面,过滤效率差;B 以范围字段打头同样无法支持按 stars 排序。

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 ↗