在使用springdata 构建mongodb聚合分页查询时,由于擅自创建PageImpl而引发的分页血案。。
现象:后台得到的总记录数不正常,数据库查询19条,接口查询返回29条
事发现场:
Aggregation aggregation = Aggregation.newAggregation(
Aggregation.sort(sort), //排序
Aggregation.lookup("cps_config", "configId", "id", "configModel"),//关联表
Aggregation.match(criteria),//查询条件
Aggregation.skip(skip), //跳过文档数量
Aggregation.limit(pageSize)//每页显示数量
);
AggregationResults<CpsConfigDetail> queryResult = mongoTemplate
.aggregate(aggregation, "cps_config", CpsConfigDetail.class);
AggregationResults<CpsConfigDetail> countResult = mongoTemplate
.aggregate(countAggregation, "cps_config", CpsConfigDetail.class);
Page<CpsConfigDetail> pager;
if(!CollectionUtils.isEmpty(que