Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ISODate is not defined

I am trying to get results from mongodb using nodejs/mongoose.

var dateStr = new Date(year,month,day,0,0,0); var nextDate = new Date(year,month,day,23,59,59);  GPSData.find({"createdAt" : { $gte : new ISODate(dateStr), $lte:  new ISODate(nextDate) }}, function(err, data) {   if(err)     console.log(err);  }); 

Error: ISODate is not defined

like image 842
coure2011 Avatar asked Jan 13 '12 09:01

coure2011


People also ask

How do I use ISODate in Python?

To get an ISO 8601 date in string format in Python 3, you can simply use the isoformat function. It returns the date in the ISO 8601 format. For example, if you give it the date 31/12/2017, it'll give you the string '2017-12-31T00:00:00'.

What is ISODate in Mongodb?

You can specify a particular date by passing an ISO-8601 date string with a year within the inclusive range 0 through 9999 to the new Date() constructor or the ISODate() function. These functions accept the following formats: new Date("<YYYY-mm-dd>") returns the ISODate with the specified date.

What is ISODate in Javascript?

The toISOString() method returns a string in simplified extended ISO format (ISO 8601), which is always 24 or 27 characters long ( YYYY-MM-DDTHH:mm:ss. sssZ or ±YYYYYY-MM-DDTHH:mm:ss. sssZ , respectively). The timezone is always zero UTC offset, as denoted by the suffix Z .


2 Answers

Note that ISODate is a part of MongoDB and is not available in your case. You should be using Date instead and the MongoDB drivers(e.g. the Mongoose ORM that you are currently using) will take care of the type conversion between Date and ISODate behind the scene.

like image 73
qiao Avatar answered Sep 24 '22 16:09

qiao


In my case, I was converting a query with ISODates

let dateString = "2014-01-22T14:56:59.301Z";  $gte : ISODate( dateString ) 

in node.js is

$gte : new Date( dateString ) 
like image 43
hestellezg Avatar answered Sep 20 '22 16:09

hestellezg