I am working with a basic mongodb database that includes two key fields:
date
and value
In my node project using mongoose, I have the following code to retrieve readings within a specific date range:
Reading.find({
date: {
$gte: startDate,
$lte: endDate
}
}).select('value date')
Now, I have a requirement to fetch readings at a particular time of the day. While this could be implemented on the frontend, I am considering the possibility of optimizing the process at the database level.
Is there a way to achieve this type of query?
Reading.find({
date: {
$gte: startDate,
$lte: endDate
},
$hour: {
$gte: 18,
$lte: 24
}
}).select('value date')