MongoDB DBA · Question 60 · Multiple choice

60. Consider the following read commands that are sent to your sharded cluster: Query A db.users.find({"userId": <String>}) Query B db.users.find({"last_login": <ISODate>, "userId": <String>}) Query C db.users.aggregate([ {"$match": {"last_login": <ISODate>, "isActive": true}}, {"$group": { "_id": "$userId", "count": {"$sum": 1} } } ]) The collection users has been sharded with the following command: sh.shardCollection( "app.users", { "userId": 1, "last_login": 1, "isActive": 1 } ) Given the chosen shard key, which queries will be routed in the sharded cluster? Check all that apply:

Answer options

  1. A.
    A
  2. B.
    B
  3. C.
    C

Answer confidence: High

Correct answer: A, B

Explanation language: Chinese

定向路由要求查询包含分片键的前缀字段:查询 A 只有 userId(前缀)可以定向;查询 B 虽然字段顺序不同,但 userId 与 last_login 都是等值条件,两个前缀字段齐全,仍可算出目标 chunk 范围。查询 C 只过滤 last_login、isActive,缺少前缀 userId,无法定位 chunk,只能广播。

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 ↗