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 才支持 管道聚合。