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

后端 未结 3 1689
醉酒成梦
醉酒成梦 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 16:59

    Mongodb 4.0 has introduced $toDate aggregation, so you can try with it

    db.collection.aggregate([
      { "$project": {
        "toDate": {
          "$toDate": "$unixTimestamp"
        }
      }}
    ])
    

    Try it here

提交回复
热议问题