use of org.springframework.data.mongodb.core.aggregation.Aggregation in project spring-data-mongodb by spring-projects.
the class MongoTemplateUnitTests method aggregateShouldUseCollationWhenPresent.
// DATAMONGO-1518, DATAMONGO-1824
@Test
public void aggregateShouldUseCollationWhenPresent() {
Aggregation aggregation = newAggregation(project("id")).withOptions(newAggregationOptions().collation(Collation.of("fr")).build());
template.aggregate(aggregation, AutogenerateableId.class, Document.class);
verify(aggregateIterable).collation(eq(com.mongodb.client.model.Collation.builder().locale("fr").build()));
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project spring-data-mongodb by spring-projects.
the class MongoTemplateUnitTests method aggregateShouldUseBatchSizeWhenPresent.
// DATAMONGO-1824
@Test
public void aggregateShouldUseBatchSizeWhenPresent() {
Aggregation aggregation = newAggregation(project("id")).withOptions(newAggregationOptions().collation(Collation.of("fr")).cursorBatchSize(100).build());
template.aggregate(aggregation, AutogenerateableId.class, Document.class);
verify(aggregateIterable).batchSize(100);
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class CorruptionRiskDashboardIndicatorsStatsController method totalProjectsByYear.
@ApiOperation(value = "Count total projects by year/month.")
@RequestMapping(value = "/api/totalProjectsByYear", method = { RequestMethod.POST, RequestMethod.GET }, produces = "application/json")
public List<DBObject> totalProjectsByYear(final YearFilterPagingRequest filter) {
DBObject project1 = new BasicDBObject();
addYearlyMonthlyProjection(filter, project1, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF);
project1.put(Fields.UNDERSCORE_ID, 0);
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), new CustomProjectionOperation(project1), group(getYearlyMonthlyGroupingFields(filter)).count().as(Keys.PROJECT_COUNT), transformYearlyGrouping(filter).andInclude(Keys.PROJECT_COUNT), getSortByYearMonth(filter));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> list = results.getMappedResults();
return list;
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class CorruptionRiskDashboardIndicatorsStatsController method totalIndicatorsByIndicatorType.
private List<DBObject> totalIndicatorsByIndicatorType(String statsProperty, final YearFilterPagingRequest filter) {
Aggregation agg = newAggregation(match(where("flags." + statsProperty + ".0").exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), unwind("flags." + statsProperty), project("flags." + statsProperty), group(statsProperty + ".type").sum(statsProperty + ".count").as(Keys.INDICATOR_COUNT), project(Keys.INDICATOR_COUNT).and(Fields.UNDERSCORE_ID).as(Keys.TYPE).andExclude(Fields.UNDERSCORE_ID), sort(Sort.Direction.ASC, "type"));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> list = results.getMappedResults();
return list;
}
use of org.springframework.data.mongodb.core.aggregation.Aggregation in project ocvn by devgateway.
the class CorruptionRiskDashboardIndicatorsStatsController method totalProjectsByIndicatorTypeByYear.
private List<DBObject> totalProjectsByIndicatorTypeByYear(String statsProperty, final YearFilterPagingRequest filter) {
DBObject project1 = new BasicDBObject();
addYearlyMonthlyProjection(filter, project1, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE_REF);
project1.put("stats", "$flags." + statsProperty);
project1.put(Fields.UNDERSCORE_ID, 0);
Aggregation agg = newAggregation(match(where(MongoConstants.FieldNames.TENDER_PERIOD_START_DATE).exists(true).and("flags." + statsProperty + ".0").exists(true).andOperator(getYearDefaultFilterCriteria(filter, MongoConstants.FieldNames.TENDER_PERIOD_START_DATE))), unwind("flags." + statsProperty), new CustomProjectionOperation(project1), group(getYearlyMonthlyGroupingFields(filter, "stats.type")).sum("stats.count").as(statsProperty.equals(ELIGIBLE_STATS) ? Keys.ELIGIBLE_COUNT : Keys.FLAGGED_COUNT).count().as(statsProperty.equals(ELIGIBLE_STATS) ? Keys.ELIGIBLE_PROJECT_COUNT : Keys.FLAGGED_PROJECT_COUNT), getSortByYearMonthWhenOtherGroups(filter, "_id.type"));
AggregationResults<DBObject> results = mongoTemplate.aggregate(agg, "release", DBObject.class);
List<DBObject> list = results.getMappedResults();
return list;
}
Aggregations