I'm clear on how to query documents within a range, but if I want, say, all docs in a collection created at 3PM (assuming I have a field with that stored of course - lets call it createdAt
), what would that query look like? At present these dates are stored in my collection as JavasSript Date objects.
CodePudding user response:
You can do it like this:
db.collection.aggregate([
{
"$match": {
"$expr": {
"$eq": [
{
"$hour": "$createdAt"
},
15
]
}
}
}
])