MongoDB DBA · Question 278 · Multiple choice

56. Consider a collection called sample which is sharded using the following shard key: { "a": 1 , "b": 1 } Which of the following queries will enable a mongos to target queries at specific shards rather than doing a scatter gather query? Check all that apply:

Answer options

  1. A.
    db.sample.find( { "b": { "$gt": 5 } )
  2. B.
    db.sample.find( { "a": { "$lte": 7 } } )
  3. C.
    db.sample.find( { "a": 12, "b": { "$gt": "jello" } } )

Answer confidence: High

Correct answer: B, C

Explanation language: Chinese

分片键是 {a:1,b:1},只有包含前缀 a 的查询才能被 mongos 定向裁剪到部分分片:B 是对前缀 a 的范围查询、C 是 a 等值加 b 范围,二者都能定向(B 可能命中多个分片,但不是全集群广播)。A 只查 b、缺少前缀 a,只能 scatter-gather 广播到所有分片。

Papers containing this question

This question appears in 6 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 ↗