MongoTemplate --- The cursor option is required, except for aggregate with the explain argument

The ‘cursor’ option is required, except for aggregate with the explain argument

mongoTemplate –>聚合报错:

    Aggregation agg = Aggregation.newAggregation(
                Aggregation.match(getCondition(year,month)),
                Aggregation.group("$Year", "$Month").sum("$Sales").as("Sales"),
                Aggregation.sort(Sort.Direction.ASC, "Year", "Month"));

写的都对,但是不能跑通,原因是对应包版本不对。
支持聚合管道的mongoTemplate 的 spring data mongo 最低也要是 如图版本
这里写图片描述
遇见错误一定要看几遍,如果不是对应的代码错误,就看看是否是代码的
原因如下:
这里写图片描述

这里写图片描述

至少在 10.11 才支持 管道聚合。

猜你喜欢

转载自blog.csdn.net/qq_36324685/article/details/80767928