new Date() in aggregate $project

后端 未结 3 1085
迷失自我
迷失自我 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 18:01

    to be able to add a timestamp field from the document, you can do this, given:

    {"ts": 1400512120100}
    

    to aggregate as a date:

    db.foo.aggregate({
       $project: {
           date: { $add: [new Date(0), "$ts"] }
       }
    })
    

提交回复
热议问题