1

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.

Nicholas K
  • 15,148
  • 7
  • 31
  • 57
Gunjan Patel
  • 2,342
  • 4
  • 24
  • 45

2 Answers2

1

Sorry, solved!! . Get it. I just need to remove ISODate string.

Gunjan Patel
  • 2,342
  • 4
  • 24
  • 45
0

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}` 
   } })
Vikas
  • 1
  • 2