java – Spring Mongo>如何从Aggregation获取列表AggregationOperations

前端之家收集整理的这篇文章主要介绍了java – Spring Mongo>如何从Aggregation获取列表AggregationOperations前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我有一个函数接收聚合聚合作为参数.

我想从聚合中获取所有AggregationOperation.有什么办法吗?

public Aggregation newCustomAggregation(Aggregation aggregation,Criteria c) {
    // How to get list operation aggregation there?
    listOperation.push(Aggregation.match(c));
    return Aggregation
            .newAggregation(listOperations);
}

我的目的是使用我的自定义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);
 }

猜你在找的Java相关文章