MongoDB DBA · Question 124 · Multiple choice

8. You have a very large movies collection with the following indexes: [ { "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({"viewerRating": 7})
  2. B.
    db.movies.find({"mpaaRating": "PG"})
  3. C.
    db.movies.find({"viewerRating": 7, "mpaaRating": "G"})

Answer confidence: Medium

Correct answer: C

Explanation language: Chinese

部分索引只有在查询谓词能保证是 partialFilterExpression 的子集时才能使用:C 中的 viewerRating: 7 蕴含 viewerRating >= 7,是过滤条件的子集,因此可以用 mpaaRating 这个部分索引定位,再用 FETCH 复核 viewerRating。A 只按 viewerRating 过滤,而索引键里根本没有这个字段,用不上;B 只按 mpaaRating 过滤,无法保证满足 viewerRating >= 7,用部分索引会漏掉 viewerRating < 7 的文档,所以也不能用。

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 ↗