首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >使用MongoDB graphLookup的AggregateFluentExtensions

使用MongoDB graphLookup的AggregateFluentExtensions
EN

Stack Overflow用户
提问于 2018-10-05 16:35:24
回答 1查看 986关注 0票数 0

我一直试图使用使用AggregateFluentExtensions.的最新C#驱动程序来执行MongoDB graphLookup根据文档:该方法接收一系列参数,我无法找到使其工作的方法。

有人用过它,可以帮我举个例子吗?

这是我的聚合的json版本:

代码语言:javascript
复制
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
            }
        }
    ]
);

谢谢!

EN

回答 1

Stack Overflow用户

发布于 2019-03-22 14:36:10

(晚会晚些时候,我希望这能帮到别人。)

我已经使用了AppendStage()方法,您可以尝试如下:

代码语言:javascript
复制
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);
票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52669936

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档