这是我的收藏集
{ "_id" : 1, "name" : "Dev" }
{ "_id" : 2, "name" : "Eliot", "reportsTo" : "Dev" }
{ "_id" : 3, "name" : "Ron", "reportsTo" : "Eliot" }
{ "_id" : 4, "name" : "Andrew", "reportsTo" : "Eliot" }
{ "_id" : 5, "name" : "Asya", "reportsTo" : "Ron" }
{ "_id" : 6, "name" : "Dan", "reportsTo" : "Andrew" }
由于MongoDB最近引入了graphLookup,我试图使用mongooose查找查询以获取如下输出
{ "_id" : 1,
"name" : "Dev"
"sub" : [{ "_id" : 2,
"name" : "Eliot"
"sub" : [{ "_id" : 3,
"name" : "Ron"
"sub" : [{ "_id" : 5,
"name" : "Asya"
"sub" : []
}]
},
{ "_id" : 4,
"name" : "Andrew"
"sub" : [{ "_id" : 6,
"name" : "Dan"
"sub" : []
}]
}
]
}]
}