MongoDB DBA · Question 412 · Single choice

Consider the following aggregation pipeline: use services db.restaurants.aggregate( [ { "$project": { "avgRating": { "$avg": "$reviews.rating" } } }, { "$match": { "avgRating": { "$gte": 7 } } }, { "$sort": { "avgRating": -1 } } ] ) Assume this pipeline is run against a sharded collection. The $sort stage requires a SHARD_MERGE operation. Where does the SHARD_MERGE happen? Choose the best answer:

Answer options

  1. A.
    The shard containing documents with the lowest avgRating values
  2. B.
    A random shard
  3. C.
    Each individual shard
  4. D.
    The mongos

Answer confidence: High

Correct answer: D

Explanation language: Chinese

$project 与 $match 可以在各分片并行执行,但 $sort 需要把各分片的部分结果汇总后统一排序(SHARD_MERGE),这个归并阶段在 mongos 上完成。只有在管道含 $out 或 $lookup 时归并才改在集合的 primary shard 上进行,本题管道没有这两个阶段,因此 B、C、D 都不对。

Papers containing this question

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