I want to create an Aggregation that can be used in MongoOperations's aggregate() function. So for creating the Aggregation, I used a list of AggregationOperation as follows:
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);
But doing this, i am getting a compile time error at the last line as follows:
The constructor Aggregation(List) is not visible
The reason is that because the Aggregation(List) constructor is having protected access. Is there any i can pass my list of AggregationOperation to create an aggregation? Any suggestion?
Here is the solution which worked well:
And there is a need to implement the result case i.e. AggregationFactoryResult as follows: