Hello I have this collection, with parent references, I need to do self join on this collection, so that output will contain the children to maximum depth in one document and also get the output based on "Type" field.
{
"DescId" : "1",
"Desc" : "Testing",
"ParentId" : "null",
"Order" : 1.0,
"Type" : "A",
"Parent" : null
}
{
"DescId" : "1.1",
"Desc" : "Testing Child 1",
"ParentId" : "1",
"Order" : 1.0,
"Type" : "B",
"Parent" : "Testing"
}
{
"DescId" : "1.2",
"Desc" : "Testing Child 2",
"ParentId" : "1",
"Order" : 2.0,
"Type" : "B",
"Parent" : "Testing"
}
{
"DescId" : "1.1.1",
"Desc" : "Testing grand child 1",
"ParentId" : "1.1",
"Order" : 1.0,
"Type" : "C",
"Parent" : "Testing Child 1"
}
At present I have this output based on answer given to my previous question:
{
"ADescId" : "1",
"ADesc" : "Testing"
}
{
"BDescId" : "1.1",
"BDesc" : "Testing child 1"
}
{
"BDescId" : "1.2",
"BDesc" : "Testing Child 2"
}
{
"CDescId" : "1.1.1",
"CDesc" : "Testing grandchild 1"
}
I have tried doing $graphlookup aggregation on this collection, somehow data seems to get messed up. Please let me know if there is a way to achieve this. Thanks.
Desired output:
{
"ADescId" : "1",
"ADesc" : "Testing",
"BDescId" : "1.1",
"BDesc" : "Testing child 1",
"CDescId" : "1.1.1",
"CDesc" : "Testing grandchild 1"
}
{
"ADescId" : "1",
"ADesc" : "Testing",
"BDescId" : "1.2",
"BDesc" : "Testing Child 2"
}