Spring mongodb: 聚合无法指定 graphLookup.maxDepth
Spring mongodb: Aggregation unable to specify graphLookup.maxDepth
我最近更新到最新的 spring mongodb 1.10 以试用新的 $graphLookup
聚合器。但是,我似乎无法指定 graphLookup
的所有参数。
具体我可以设置startWith
、connectFrom
、connectTo
成功,但是as
、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
返回的 class 似乎是静态的和最终的。
是否有其他设置方法 maxDepth
,或者这是一个错误?
这仍然是一个发布候选版本,但看起来像是一个错误。您可以使用 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);
}
};
我最近更新到最新的 spring mongodb 1.10 以试用新的 $graphLookup
聚合器。但是,我似乎无法指定 graphLookup
的所有参数。
具体我可以设置startWith
、connectFrom
、connectTo
成功,但是as
、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
返回的 class 似乎是静态的和最终的。
是否有其他设置方法 maxDepth
,或者这是一个错误?
这仍然是一个发布候选版本,但看起来像是一个错误。您可以使用 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);
}
};