I have a JSON format like below:
[
{
"_id": "566acc776cc532d5368db0f5",
"date": "2015-12-01T13:02:30.720Z",
"title1": "title"
}
]
Need some nodejs query that returns data between two dates. I also tried in find query object
as follow but get nothing. How to match please tell me.
{
date: {
$gte:ISODate("2013-11-19T14:00:00Z"),
$lt: ISODate("2013-11-19T20:00:00Z")
}
}
Some ISODate Error. Please give me a suggestion.
Sorry, solved!! . Get it. I just need to remove ISODate
string.
I hope you do like this to resolve the Issue.
// Fetch Document By Current Date
const startDate =new Date(new Date().setUTCHours(0, 0, 0, 0)).toISOString();
const endDate =new Date(new Date().setUTCHours(23, 59, 59, 999)).toISOString();
// Fetch Document By Specific Date (findDate is Parameter)
const startDate =new Date(new Date(findDate).setUTCHours(0, 0, 0, 0)).toISOString();
const endDate =new Date(new Date(findDate).setUTCHours(23, 59, 59, 999)).toISOString();
let result = yourModel.find({date: {
$gte:`${startDate}`,
$lt: `${endDate}`
} })
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.