Database

[{"_id":1,"name":"l1","children":[2,3]},{"_id":2,"name":"l2a","children":[]},{"_id":3,"name":"l2b","children":[5]},{"_id":4,"name":"l3a","children":[]},{"_id":5,"name":"l3b","children":[]}]

Query

db.collection.aggregate([{"$match":{"_id":1}},{"$lookup":{"from":"collection","let":{"name":"$name","children":"$children"},"pipeline":[{"$match":{"$expr":{"$in":["$_id","$$children"]}}},{"$addFields":{"route":{"$concat":["$$name","/","$name"]}}},{"$lookup":{"from":"collection","let":{"route":"$route","children":"$children"},"pipeline":[{"$match":{"$expr":{"$in":["$_id","$$children"]}}},{"$addFields":{"route":{"$concat":["$$route","/","$name"]}}}],"as":"children"}}],"as":"children"}}])

Result