【发布时间】:2019-02-07 21:58:31
【问题描述】:
以下是我的文档结构:
{
"_id":"5c59c35d8610f702d00e6f70",
"stationId":"2",
"listenerId":"807",
"streamId":"37",
"userAgentId":"7",
"botDefinitionId":"18",
"ipAddress":"50.116.14.48",
"startTime":"2018-02-06T12:51:59.000Z",
"endTime":"2018-02-06T12:53:56.000Z",
"listenLength":"117",
"totalDataUsed":"1433582",
}
使用 spring 数据 mongo,我想将它们分组到时间窗口中(比如说 15 分钟间隔)。我创建了以下工作查询:
{
'_id':{
'year':{
'$year':'$startTime'
},
'week':{
'$week':'$startTime'
},
'dayOfMonth':{
'$dayOfMonth':'$startTime'
},
'month':{
'$month':'$startTime'
},
'hour':{
'$hour':'$startTime'
},
'interval':{
'$subtract':[
{
'$minute':'$startTime'
},
{
'$mod':[
{
'$minute':'$startTime'
},
15
]
}
]
}
},
'count':{
'$sum':1
}
}
然后返回给我以下文件:
_id:{
year:2018 week:15 dayOfMonth:18 month:4 hour:18 interval:45
},
count:9
如何在 spring-data-mongo 中使用 GroupOperation 来指定这个聚合?
【问题讨论】:
标签: mongodb spring-data-mongodb