mongoTemplate 分组查询的坑

Aggregation agg = Aggregation.newAggregation(
                Aggregation.match(new Criteria().orOperator(new Criteria("to").is(ukey), new Criteria().and("fromAccount").is(ukey))),
                Aggregation.sort(Sort.Direction.DESC,"_id"),
                Aggregation.group("to","fromAccount")
        );

 Aggregation.group 要排在Aggregation.match后面,否则结果集不准确。

你可能感兴趣的:(mongo)