MongoDB DEV · Question 193 · Single choice

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

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

Answer confidence: High

Correct answer: B

Explanation language: Chinese

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

Papers containing this question

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