Database
[{"id":"A"},{"id":"B","parentId":"A"}]
Query
db.collection.aggregate([{"$match":{"id":"A"}},{"$graphLookup":{"from":"collection","startWith":"$id","connectFromField":"id","connectToField":"parentId","as":"children","depthField":"depth"}},{"$unwind":"$children"},{"$replaceRoot":{"newRoot":{id:"$children.id",depth:"$children.depth"}}}])