【发布时间】:2016-12-14 10:38:40
【问题描述】:
我想创建一个可以在 MongoOperations 的 aggregate() 函数中使用的聚合。 因此,为了创建聚合,我使用了 AggregationOperation 列表,如下所示:
ApplicationContext ctx = new AnnotationConfigApplicationContext(MongoConfig.class);
MongoOperations mongoOperation = (MongoOperations) ctx.getBean("mongoTemplate");
List<AggregationOperation> aggregationOperations = new ArrayList<AggregationOperation>();
aggregationOperations.add(new MatchOperation(Criteria.where("country").is("tigo")));
aggregationOperations.add(new UnwindOperation(Fields.field("myDetails")));
aggregationOperations.add(new MatchOperation(Criteria.where("myDetails.type").is("health")));
aggregationOperations.add(new SortOperation(new Sort(Sort.Direction.ASC, "myDetails.datetime")));
AggregationResults<AggregateFactoryResult> result = mongoOperation.aggregate(new Aggregation(aggregationOperations), "gui_data", AggregateFactoryResult.class);
但是这样做,我在最后一行得到一个编译时错误,如下所示:
构造函数 Aggregation(List) 不是 可见
原因是因为 Aggregation(List) 构造函数具有受保护的访问权限。 有没有我可以通过我的 AggregationOperation 列表来创建聚合? 有什么建议吗?
【问题讨论】:
-
AggregationResults
结果 = mongoOperation.aggregate(Aggregation.newAggregation(aggregationOperations), "gui_data", AggregateFactoryResult.class);
标签: java mongodb java-8 aggregation spring-data-mongodb