加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

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

发布时间:2020-12-15 00:44:06 所属栏目:Java 来源:网络整理
导读:我有一个函数接收聚合聚合作为参数. 我想从聚合中获取所有AggregationOperation.有什么办法吗? public Aggregation newCustomAggregation(Aggregation aggregation,Criteria c) { // How to get list operation aggregation there? listOperation.push(Aggr
我有一个函数接收聚合聚合作为参数.

我想从聚合中获取所有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);
 }

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读