mongoTemplate 聚合排序不生效问题


最近项目用到了MongoDB,在使用聚合的时候发现排序没有生效.  后来发现是sort位置原因.

public List<TrackTrace> findPoint(List<String> jobNos) {

        Sort sort = new Sort(Sort.Direction.DESC, "traceDate");
        Aggregation agg =
                Aggregation.newAggregation(
                        Aggregation.project("jobNo", "points", "traceDate", "time"),
                        Aggregation.match(Criteria.where("jobNo").in(jobNos)),
                        Aggregation.sort(sort),//在聚合之前对数据进行排序
                        Aggregation.group("jobNo")
                                .first("jobNo").as("jobNo")
                                .first("points").as("points")
                                .first("traceDate").as("traceDate")
                );
        AggregationResults<TrackTrace> durationData =
                mongoTemplate.aggregate(agg, "TrackTrace", TrackTrace.class);
        List<TrackTrace> traces = durationData.getMappedResults();
        return traces;
    }

 


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM