我最近更新了最新的MongoDB1.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")
;从春季源代码来看,connectTo GraphLookupOperationBuilder返回的类似乎是静态的和最终的。
还有其他方法来设置maxDepth,还是这是一个bug?
发布于 2017-01-27 18:55:57
这仍然是一个发布候选版本,但看起来是一个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);
}
};https://stackoverflow.com/questions/41900444
复制相似问题