new Date() in aggregate $project

后端 未结 3 1079
迷失自我
迷失自我 2020-12-28 17:34

For one of my collections, which must remain unix timestamp instead of isodate, I usually convert the timestamp with new Date(unix_timestamp).

Now I need the ne

3条回答
  •  旧巷少年郎
    2020-12-28 17:52

    Starting Mongo 4.0, this can be achieved with the $toDate aggregation operator:

    // { "ts": 1400512120100 }
    db.collection.aggregate({ $project: { date: { $toDate: "$ts" } } })
    // { "date": ISODate("2014-05-19T15:08:40.100Z") }
    

提交回复
热议问题