MongoDB DBA · Question 335 · Multiple choice

54. You have a very large movies collection with the following indexes: > db.movies.getIndexes() [ { "v" : 2, "key" : { "_id" : 1 }, "name" : "_id_", "ns" : "video.movies" }, { "v" : 2, "key" : { "mpaaRating" : 1 }, "name" : "mpaaRating_q", "ns" : "video.movies", "partialFilterExpression" : { "viewerRating" : { "$gte" : 7 } } } ] Which of the following queries will be served by these indexes? Check all that apply:

Answer options

  1. A.
    db.movies.find({"mpaaRating": "PG"})
  2. B.
    db.movies.find({"viewerRating": 7, "mpaaRating": "G"})
  3. C.
    db.movies.find({"viewerRating": 7})

Answer confidence: High

Correct answer: B

Explanation language: Chinese

部分索引只有在查询条件"包含 partialFilterExpression"时才会被使用:B 的 viewerRating:7 是 viewerRating:{$gte:7} 的子集,同时又带 mpaaRating 谓词,所以能命中 mpaaRating 这个部分索引。A 只查 mpaaRating,无法保证结果都落在 viewerRating>=7 的范围内(会漏掉 viewerRating<7 的文档),优化器不会用;C 只有 viewerRating 谓词,索引键 mpaaRating 上没有条件,只能全集合扫描。

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 ↗