mongoDB:将“时间"中的MinuteBucket显示为时间间隔的结束时间 [英] mongoDB: Show MinuteBucket in Time value as ending time for the interval
问题描述
我创建了 Mongo PlayGround
当前dateHour字段将时间除以15分钟间隔.
Currently dateHour field is dividing time by 15min interval.
例如- 如果
`"updatedAt": ISODate("2020-03-20T18:16:50.000Z")`
它显示为:
"dateHour": ISODate("2020-03-20T18:15:00Z"),
因此,前15分钟的时段代表 18:00:000z (涵盖1到15分钟)
so First 15min bucket is represented as 18:00:000z (this covers minutes from 1 to 15)
第二15分钟时段代表 18:15:000z (涵盖15至30分钟) 等等...
second 15min bucket is represented as 18:15:000z (this covers minutes from 15 to 30) and so on....
预期-
第一个15分钟的时段应显示为 18:15:000z (涵盖从1到15分钟的分钟) 第二15分钟时段应显示为 18:30:000z (涵盖15至30分钟) 等等...
First 15min bucket should be displayed as 18:15:000z (this covers minutes from 1 to 15) second 15min bucket should be displayed as 18:30:000z (this covers minutes from 15 to 30) and so on....
基本上应该显示该时间间隔的结束时间
Basically it should show ending time for that interval
推荐答案
您正在使用 $ ceil 代替:
You're using $trunc which is this case converts the result of $divide
into lower minuteBucket, you can use $ceil instead:
minuteBucket: {
$ceil: {
$divide: [ { $minute: "$updatedAt" }, 15.0 ]
}
},
这篇关于mongoDB:将“时间"中的MinuteBucket显示为时间间隔的结束时间的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!