基本上我有这种类型的数据,我希望使用$ graphLookup
获得关系{_id: "111", pin: "8018", introducer: ""}
{_id: "222", pin: "042f", introducer: "8018"}
{_id: "333", pin: "1234", introducer: "042f"}
我的输出应该是
{_id: "111", pin: "8018", introducer: "", treeView: []}
{_id: "222", pin: "042f", introducer: "8018", treeView: [{_id: "111", pin: "8018", introducer: ""}]}
{_id: "333", pin: "1234", introducer: "042f", treeView: [{_id: "111", pin: "8018", introducer: ""},{_id: "222", pin: "042f", introducer: "8018"} ]}
我的代码
userSchema.statics.getChildren = function(user){
return this.aggregate([
{ $graphLookup: {
from: "userSchema",
startWith: "$introducer",
connectFromField: "introducer",
connectToField: "pin",
as: "treeView"
}
}
]);
};
但是我只获得了treeView的空白数组。请帮忙。