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:
题目选项
- A.The shard containing documents with the lowest avgRating values
- B.A random shard
- C.Each individual shard
- D.The mongos
答案置信度:高
正确答案:D
解析语言:中文
$project 与 $match 可以在各分片并行执行,但 $sort 需要把各分片的部分结果汇总后统一排序(SHARD_MERGE),这个归并阶段在 mongos 上完成。只有在管道含 $out 或 $lookup 时归并才改在集合的 primary shard 上进行,本题管道没有这两个阶段,因此 B、C、D 都不对。