将mongodb聚合查询转换为spring-data-mongodb

时间:2015-07-20 08:42:16

标签: spring-data-mongodb

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

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

由于

1 个答案:

答案 0 :(得分:-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"));

就是这样。