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
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'.
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.
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 .
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.
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 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With