【问题标题】:MongoDB graphLookup using AggregateFluentExtensionsMongoDB graphLookup 使用 AggregateFluentExtensions
【发布时间】:2018-10-05 16:35:24
【问题描述】:

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

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

这是我的聚合的 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
            }
        }
    ]
);

谢谢!

【问题讨论】:

    标签: c# mongodb aggregation-framework


    【解决方案1】:

    (聚会晚了,我希望它对某人有所帮助。)

    我用过 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);
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多