我希望从图查询聚合中输出未指定数量的嵌套数组。
我有数据收集:
[
{ _id: 1, name: 'AA' },
{ _id: 2, name: 'BB', parent: 1, ancestors: [1] },
{ _id: 3, name: 'CC' },
{ _id: 4, name: 'DD', parent: 3, ancestors: [3] },
{ _id: 5, name: 'DD', parent: 4, ancestors: [3, 4] },
{ _id: 6, name: 'FF', parent: 5, ancestors: [3, 4, 5] }
...,
...,
... ]
如何以图表形式显示查找汇总以输出以生成未指定的层次结构,如下所示:
{
"_id" : 3,
"name" : "CC",
"children" : [
{
"_id" : 4,
"name" : "DD",
"parent" : 3,
"ancestors" : [
3
],
"children":[
{
"_id" : 5,
"name" : "DD",
"parent" : 4,
"ancestors" : [
3,
4
],
children:[
{
...,
children:[...]
}
]
},
]
},
]
}*
我希望有人能帮助我,谢谢。