Pipeline Practice

Trace the category hierarchy

`$graphLookup` follows a relationship repeatedly. The starting value enters the first lookup, then `connectFromField` supplies the value for the next hop until the chain ends or a configured limit is reached.

For every leaf category, traverse its `parentId` chain through the `categories` collection. Return `category`, `parentId`, and `ancestorDepth`, sorted by category name.

Expected result: Five leaf-category records, each with an ancestor depth of two.

Example pipeline syntax

[
  { $match: { kind: "leaf" } }
]