MongoDB DEV · Question 89 · Multiple choice

You have created the following index on a collection called people: db.people.createIndex({ lastName : 1, firstName : 1, birthDate : -1 }) Which of the following queries can use the above index for sorting? Check all that apply:

Answer options

  1. A.
    db.people.find().sort({ birthDate : -1 })
  2. B.
    db.people.find().sort({ lastName : -1, firstName : -1, birthDate : -1 })
  3. C.
    db.people.find({ lastName : "Jones" } ).sort({ firstName : 1 })

Answer confidence: High

Correct answer: C

Explanation language: Chinese

该索引正向顺序是 (lastName 升, firstName 升, birthDate 降),反向扫描则是 (lastName 降, firstName 降, birthDate 升)。A 在 lastName 等值后按 firstName:1 排序,方向与索引前缀一致,可用索引;B 缺首字段 lastName,无法用索引排序;C 三字段全降序既不等于索引方向,也不是它的"完全反向"(完全反向时 birthDate 应为升序),只能走内存排序。

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 ↗