【发布时间】:2020-11-11 01:02:35
【问题描述】:
我想在我的 Spring Boot 应用程序中创建一个聚合查询。
查询:
db.mycollection.aggregate(
{
$match : {
timeStamp: {$gte: ISODate("2020-07-13T00:00:00.000Z"), $lt: ISODate("2020-07-13T23:59:59.000Z")}
}
},
{ "$project": {
"h":{"$hour": { "$add": [ "$timeStamp", 5.5 * 60 * 60 * 1000 ] }}
}},
{ "$group":{
"_id": "$h",
"total":{ "$sum": 1}
}
}
)
我在我的 Spring Boot 应用程序中创建了以下聚合对象
Aggregation violationHourlyData = Aggregation.newAggregation(
Aggregation.match(Criteria.where("timeStamp").gte(fromDate).lte(toDate)),
Aggregation.project("_id").andExpression( "hour(timeStamp)").as("h"),
Aggregation.group("h").count().as("count")
);
在上面的对象中,我想在查询中提到的时间戳中添加一些时间。
谢谢
【问题讨论】:
标签: mongodb spring-boot aggregation-framework spring-data-mongodb