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);
 }

相关文章

应用场景 C端用户提交工单、工单创建完成之后、会发布一条工...
线程类,设置有一个公共资源 package cn.org.chris.concurre...
Java中的数字(带有0前缀和字符串)
在Java 9中使用JLink的目的是什么?
Java Stream API Filter(过滤器)
在Java中找到正数和负数数组元素的数量