I have a tree structure.
node collection.
{
_id: ‘123’,
}
{
_id: ‘444’,
}
{
_id: ‘555’,
}
{
_id: ‘666’,
}
hierarchy collection.
{
_id: ‘333’,
parent: ‘123’,
child: ‘444’,
}
{
_id: ‘344’,
parent: ‘123’,
child: ‘555’,
}
{
_id: ‘344’,
parent: ‘555’,
child: ‘666’,
}
Something similar to the above. Now i need to recursively fetch the entire tree.
I want the result to be a single nested json.
{
_id: '123',
subTasks: [
{
_id: '444',
},
{
_id: '555',
subTasks: [
{
_id: '666',
}
]
}
]
}
I tried using graph lookup. But i’m not getting the desired result
{ from: 'hierarchies', startWith: '$_id' , connectFromField: 'parent', connectToField: 'child', as: 'subTasks', maxDepth: 3, }