AggregateGraphLookupOptions mongo GraphLookup集

时间:2018-07-05 12:21:04

标签: c# mongodb aggregate

如何将选项设置为 GraphLookup , 现在设置选项,我无法设置通用类型。

  var options = new **AggregateGraphLookupOptions<BsonDocument, BsonDocument, BsonDocument>**
            {
                MaxDepth = 2,
            };

var ss1 = aggregate.GraphLookup(this.EntitiesCol, "To", "From", startField, "destinations", **options**);

在ss1之后,我用于匹配和分组...

错误:

  

严重性代码描述项目文件行抑制状态   错误CS0411方法的类型参数   'IAggregateFluent.GraphLookup(IMongoCollection,FieldDefinition,FieldDefinition,   AggregateExpressionDefinition,   FieldDefinition,FieldDefinition,   AggregateGraphLookupOptions)'不能为   从用法推断。尝试指定类型参数   明确地。 Abc.eStepControl.Infrastructure F:\ ABC \ eStepControl \ eStepControl \ EngineGit \ dev \ eStepControl.Engine \ src \ eStepControl.Infrastructure \ Repositories \ EdgesRepository.cs 684有效

1 个答案:

答案 0 :(得分:0)

使用AppendStage()方法添加graphLookup阶段,如下所示:

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);