I have mongo documents containing a field createAt date. I would like to search for all documents where
the hour of createAt at 8 o'clock in the morning of everyday (between 8:00am and 8:00am)
, but I have no clue how to write the query.
In MySQL I can write it like this:
select * from table where hour(createAt)= 8
CodePudding user response:
db.collection.find({
$expr: {
$eq: [
{
$hour: "$createdAt"
},
8
]
}
})
CodePudding user response:
Your question has already been resolved.
I wrote you an example on the playground.