/**
*mongoTemplate 聚合分组统计返回分组列表
*/
public Page<Log> groupStatistics(String compCampId, Long productId, Integer page, Integer size) {
if (page<1){page=1;}
Integer startRows = (page - 1) * size;
Sort sort = new Sort(Sort.Direction.DESC,"create_time");
List<String> patterns =new ArrayList<>();
patterns.add("scan_code_action");
patterns.add("pay_wechat_success");
Criteria criteria = Criteria.where("operation_name").in(patterns);
if (productId != null ){
criteria.and("module_id").is(productId);
}
if (compCampId != null ){
criteria.and("activity_id").is(compCampId);
}
SpringDataPageable pageable = new SpringDataPageable();
//开始页
pageable.setPagenumber(page);
//每页条数
pageable.setPagesize(size);
//排序
pageable.setSort(sort);
List<AggregationOperation> operations = new ArrayList<>();
operations.add(Aggregation.match(criteria));
op
mongoTemplate 聚合分组统计,aggregate分页
最新推荐文章于 2025-05-30 11:11:05 发布

本文详细介绍了如何使用MongoTemplate进行聚合查询,实现数据的分组统计,并结合分页功能,帮助读者掌握MongoDB在Java应用中的高级查询技巧。
最低0.47元/天 解锁文章
1012

被折叠的 条评论
为什么被折叠?



