【问题标题】:translate mongodb aggregation query to spring-data-mongodb将 mongodb 聚合查询转换为 spring-data-mongodb
【发布时间】:2015-10-09 07:37:05
【问题描述】:

是否可以将此 mongo shell 聚合查询转换为 spring-data?

db.getCollection("X").aggregate([
    {
        $group: {
            _id: {
                year: {
                    $year: "$happenedAt"
                },
                month: {
                    $month: "$happenedAt"
                },
                day: {
                    $dayOfMonth: "$happenedAt"
                }
            },
            count: {
                $sum: 1
            }
        }
    }
])

谢谢

【问题讨论】:

    标签: spring-data-mongodb


    【解决方案1】:
    Criteria c=new Criteria(Criteria.where("year").is(y).and("month").is(m).and("day").is(d));
    Aggregration a=newAggregration(match(c),group("year","month","day").count().as("total"));
    

    就是这样。

    【讨论】:

      猜你喜欢
      • 2018-01-08
      • 1970-01-01
      • 1970-01-01
      • 2020-10-14
      • 2021-09-03
      • 2014-07-31
      • 2017-05-11
      • 1970-01-01
      • 2015-12-17
      相关资源
      最近更新 更多