We stored a date using unix timestamp in MongoDB, how do I get the date when I do the query? Is there a way to display timestamp in ISODate format?
In the Mongo console you can create a JavaScript Date
object from a timestamp before the document is printed to the screen:
> db.stuff.find().forEach(function (doc) {
doc["timestamp_field"] = new Date(doc["timestamp_field"])
printjson(doc)
})
Be careful with that code, unlike a regular find()
it will not page the results but print every matching document without pausing.