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:
Answer options
- A.$count
- B.$graphLookup
- C.$lookup
- D.$replaceRoot
- E.$bucket
Answer confidence: High
Correct answer: B
Explanation language: Chinese
用 from / startWith / connectFromField / connectToField / as / maxDepth 做递归图遍历(逐级找祖先)只有 $graphLookup 支持。$lookup 是单层的非递归连接、没有 maxDepth 参数,$bucket 是分桶、$count 是计数、$replaceRoot 是替换根文档,都无法完成多层递归查找。