mongodb 时间分组 聚合

在cmd里面,用原生mongodb的查询可以成功分组,按照30s分组,查询到两条数据,
但是放到idea里面用mongodbtemplate查询,只能查询到一条数据,分组没成功?有大佬指导下吗?
idea里面写法:
Aggregation.newAggregation(

            Aggregation.match(Criteria.where("appendtime").gte(sdf.parse(startTime)).lte(sdf.parse(endTime))),
            Aggregation.group("_id:" + "{ $subtract: [ { $subtract: [ '$appendtime', new Date( '1970-01-01') ] },"  +
            "{ $mod: [{ $subtract: [ '$appendtime', new Date('1970-01-01') ] },1000 * 60 * 30]}]}").first("fe").as("fe")
           , Aggregation.sort(Sort.Direction.DESC,"_id")

图片描述

阅读 1.9k
撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进