java 操作mongodb Aggregation 分组查询及 排序

直接上代码:
Aggregation agg = Aggregation.newAggregation(Resional.class,
Aggregation.match(Criteria.where("createTime").gte(req.getStartTime())
.lte(req.getEndTime())),
Aggregation.group("createUserId").count().as("count"),
Aggregation.sort(Sort.Direction.DESC, "count")
);
AggregationResults<ExportExcelResourceListDto> aggregate =
mongoTemplate.aggregate((TypedAggregation<?>) agg,
ExportExcelResourceListDto.class);
return aggregate.getMappedResults();


posted @ 2021-12-04 15:42  星空物语之韵  阅读(3322)  评论(0编辑  收藏  举报