我一直试图使用使用AggregateFluentExtensions.的最新C#驱动程序来执行MongoDB graphLookup根据文档:该方法接收一系列参数,我无法找到使其工作的方法。
有人用过它,可以帮我举个例子吗?
这是我的聚合的json版本:
db.getCollection("Item").aggregate(
[
{
"$project" : {
"itemMasterId" : 1.0,
"parentItemId" : 1.0
}
},
{
"$graphLookup" : {
"from" : "Item",
"startWith" : "$itemMasterId",
"connectFromField" : "itemMasterId",
"connectToField" : "parentItemId",
"as" : "ancestors",
"maxDepth" : 10,
"depthField" : "depthField",
"restrictSearchWithMatch" : {
"locationId" : 26
}
}
},
{
"$project" : {
"itemMasterId" : 1.0,
"parentItemId" : 1.0,
"children.itemMasterId" : 1,
"children.parentItemId" : 1
}
}
]
);
谢谢!
发布于 2019-03-22 14:36:10
(晚会晚些时候,我希望这能帮到别人。)
我已经使用了AppendStage()方法,您可以尝试如下:
var graphLookupStage = new BsonDocument("$graphLookup",
new BsonDocument
{
{ "from", "someCollection" },
{ "startWith", "$reportsTo" },
{ "connectFromField", "reportsTo"},
{ "connectToField", "name" },
{ "as", "reportingHierarchy" },
{ "maxDepth", 1 },
{ "depthField", "depthField" } //optional
});
var result = collection.Aggregate().AppendStage<BsonDocument>(graphLookupStage);https://stackoverflow.com/questions/52669936
复制相似问题