Ive been stuck in a situation where I need to fetch records from mongo db according to date
so i have start_date
as 2017-08-20
and end_date
as 2017-08-21
coming from the front end. I have a record like this
{
"success": 1,
"total": 1,
"request": 0,
"response": "17",
"username": "comp1",
"timestamp": "2017-08-21T05:13:32.000Z"
}
now i want to run the mongoose query like this
Model.find(query)
from node js code so that i get the data from 2017-08-20
starting from 00:00
to 2017-08-21
ending to 23:59
need to know what query
i need to put to get the records of the selected date, Thanks in Advance
You could try a query like this:
Model.find({
timestamp: {
$gte: ISODate("2017-08-20T00:00:00.000Z"),
$lt: ISODate("2017-08-21T00:00:00.000Z")
}
}, function(err, docs) {
// ...
})
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.