Java Spring mongodb:聚合无法指定graphLookup.maxDepth
我最近更新了最新的spring mongodb 1.10,以试用新的Java Spring mongodb:聚合无法指定graphLookup.maxDepth,java,spring,aggregation-framework,spring-data-mongodb,Java,Spring,Aggregation Framework,Spring Data Mongodb,我最近更新了最新的spring mongodb 1.10,以试用新的$graphLookup聚合器。但是,我似乎无法为graphLookup指定所有参数 具体地说,我可以成功地将startWith、connectFrom和connectTo设置为,但和maxDepth似乎不可见 这是有效的: Aggregation.graphLookup("relationships") .startWith("destination") .connectFrom("destin
$graphLookup
聚合器。但是,我似乎无法为graphLookup
指定所有参数
具体地说,我可以成功地将startWith
、connectFrom
和connectTo
设置为,但和maxDepth
似乎不可见
这是有效的:
Aggregation.graphLookup("relationships")
.startWith("destination")
.connectFrom("destination")
.connectTo("source")
;
这不是:
Aggregation.graphLookup("relationships")
.startWith("destination")
.connectFrom("destination")
.connectTo("source")
.maxDepth("2")
.as("relationshipGraph")
;
查看spring源代码,connectTo
GraphLookupOperationBuilder
返回的类似乎是静态的和最终的
是否有其他方法设置maxDepth
,或者这是一个bug?这仍然是一个候选版本,但看起来像是一个bug。您可以使用AggregationOperation
使用下面的解决方法,它允许您创建聚合管道
AggregationOperation aggregation = new AggregationOperation() {
@Override
public DBObject toDBObject(AggregationOperationContext aggregationOperationContext) {
DBObject graphLookup = new BasicDBObject(
"from", "relationships"). append(
"startWith", "$destination").append(
"connectFromField", "destination").append(
"connectToField", "source").append(
"maxDepth", 2).append(
"as", "relationshipGraph");
return new BasicDBObject("$graphLookup", graphLookup);
}
};
那是一只虫子。我创建了我认为1.10是一个官方版本。不管怎样,谢谢。在此期间,我将使用此解决方法。