MongoDB DEV · 题目 193 · 单选

Consider a collection people where every document has the following fields: { "_id" : "syeda", "parents" : [ "anjali", "nalina" ] } { "_id" : "manjunath", "parents" : [ "pradhyuman", "vyasar" ] } Each document has an _id representing a single person, and an array parents representing that person's parents. Consider the following query on the people collection to find every person's parents, and grandparents (their parents' parents): db.people.aggregate([ { "AGGREGATION_STAGE": { "from": "people", "startWith": "$parents", "connectFromField": "parents", "connectToField": "_id", "as": "ancestors", "maxDepth": 1 } } ]) Which Aggregation stage should be used for the placeholder "AGGREGATION_STAGE"? Choose the best answer:

题目选项

  1. A.
    $count
  2. B.
    $graphLookup
  3. C.
    $lookup
  4. D.
    $replaceRoot
  5. E.
    $bucket

答案置信度:高

正确答案:B

解析语言:中文

用 from / startWith / connectFromField / connectToField / as / maxDepth 做递归图遍历(逐级找祖先)只有 $graphLookup 支持。$lookup 是单层的非递归连接、没有 maxDepth 参数,$bucket 是分桶、$count 是计数、$replaceRoot 是替换根文档,都无法完成多层递归查找。

所在套题

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

作者 · 作品 · 开源

作者与 MongoDB 作品

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

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

联系作者 ↗mlhp123@outlook.com

支持作者

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

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