Instead of ObjectId('82he921he982he82') its "_id":{"$oid":"82he921he982he82"} for object Ids, but I have no idea how to create a date value in a document on MongoLab :s
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.
MongoDB will store date and time information using UTC internally, but can easily convert to other timezones at time of retrieval as needed.
The best format to store date and time in MongoDB is native javascript Date() or ISO date format as it internally converts it into BSON native Date object.
The recommended way to store dates in MongoDB is to use the BSON Date data type. The. BSON Specification. refers to the Date type as the UTC datetime and is a 64-bit integer. It represents the number of milliseconds since the.
If you are using one of the drivers, you create a date via that language's Date class. For instance, in Javascript (like Node.js) it would be 'new Date(11,11,11)'. If using the MongoLab REST API or admin UI you represent dates with this syntax:
{ "$date": "2010-10-28T23:07:11Z" }
Also if an item has:
"dateAdded": {
"$date": "2012-07-30T15:26:15.321Z"
}
in one of it's entries, then you can find it by searching:
{
"dateAdded": {
"$gt": {
"$date": "2012-07-28T23:07:11Z"
}
}
}
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