我有一个函数,可以接收Aggregation aggregation
作为参数。
我想从AggregationOperation
获取所有aggregation
。有什么办法吗?
public Aggregation newCustomAggregation(Aggregation aggregation, Criteria c) {
// How to get list operation aggregation there?
listOperation.push(Aggregation.match(c));
return Aggregation
.newAggregation(listOperations);
}
我的目的是使用自定义
Aggregation
另一个新的MatchAggregation
。 最佳答案
您可以通过将聚合子类化以访问受保护的操作字段来创建自己的自定义聚合实现。
就像是
public class CustomAggregation extends Aggregation {
List<AggregationOperation> getAggregationOperations() {
return operations;
}
}
public Aggregation newCustomAggregation(Aggregation aggregation, Criteria c) {
CustomAggregation customAggregation = (CustomAggregation) aggregation;
List<AggregationOperation> listOperations = customAggregation.getAggregationOperations();
listOperations.add(Aggregation.match(c));
return Aggregation .newAggregation(listOperations);
}