Is there a way to display timestamp in unix format to ISODate?

后端 未结 3 1690
醉酒成梦
醉酒成梦 2021-02-13 16:30

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?

3条回答
  •  渐次进展
    2021-02-13 17:12

    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.

提交回复
热议问题