问题
I have created Mongo PlayGround
Currently dateHour field is dividing time by 15min interval.
For example - if
`"updatedAt": ISODate("2020-03-20T18:16:50.000Z")`
it shows as :
"dateHour": ISODate("2020-03-20T18:15:00Z"),
so First 15min bucket is represented as 18:00:000z (this covers minutes from 1 to 15)
second 15min bucket is represented as 18:15:000z (this covers minutes from 15 to 30) and so on....
Expected -
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
回答1:
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 ]
}
},
Mongo Playground
来源:https://stackoverflow.com/questions/61163597/mongodb-show-minutebucket-in-time-value-as-ending-time-for-the-interval