对某些筛选条件进行分页查询,开始每一页的有效data都不足pageSize,最后发现,aggregation 的pipeline是有先后顺序的。
错误:
agg = Aggregation.newAggregation(Aggregation.skip((curPage - 1) * pageSize), Aggregation.limit(pageSize), Aggregation.match(criteria), project);
这样是先找出每一页的data,然后再进行筛选
正确:
agg = Aggregation.newAggregation(Aggregation.match(criteria), Aggregation.skip((curPage - 1) * pageSize), Aggregation.limit(pageSize), project);
应该先筛选,再分页