I want to extract a document between a specific range of hours(between 19:01 - 06:59) of daily activity. My dateTime document is stored in ISODate.
{
"_id" : ObjectId("5ff8f5a56c3aacbab9ee0f41"),
"dateTime" : ISODate("2020-06-11T20:45:00.000Z"),
"value" : "37"
}
/* 29 */
{
"_id" : ObjectId("5ff8f5a56c3aacbab9ee0f42"),
"dateTime" : ISODate("2020-06-11T20:49:00.000Z"),
"value" : "6"
}
I tried the following query, but I am not getting any result.
db.Steps.aggregate([
{$project:{
byDay:{$dayOfMonth:{date:"$dateTime"}},
byMonth:{$month:{date:"$dateTime"}},
_id:0,
val:{$toInt:"$value"},
minutes: { $add: [
{ $multiply: [ { $hour: '$dateTime' }, 60 ] },
{ $minute: '$dateTime' }
] }}} ,
{ $match: { 'minutes' : { $gt : 19 * 60, $lt : 7 * 60 } } },
{$group:{
_id:{month:"$byMonth",day:"$byDay" },
StepsDone:{$avg:"$val"}}} ,
{$sort:{_id:1}} ]);
question from:https://stackoverflow.com/questions/65644348/querying-between-a-time-range-of-hours-in-mongodb