MongoDB DBA · 题目 412 · 单选

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:

题目选项

  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

答案置信度:高

正确答案:D

解析语言:中文

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

所在套题

此题在题库中有 2 条记录。公开详情合并相同题干和选项;完整公开题展示置信度最高的一条记录,其他题目仅展示摘要。按套学习保留每条记录原有的答案、解析和置信度。

作者 · 作品 · 开源

作者与 MongoDB 作品

专注数据平台、MongoDB 迁移同步与云运维产品研发。

有任何 MongoDB 需求,均可联系作者。

联系作者 ↗mlhp123@outlook.com

支持作者

如果题库对您有帮助,欢迎自愿扫码打赏。

支付宝扫码打赏作者打开打赏原图 ↗