Converting a mongo stored date back into milliseconds since Unix epoch when loaded?

前端 未结 5 410
名媛妹妹
名媛妹妹 2020-12-15 21:09

I am using Mongoose & Node.js for my webserver.

As a part of one of my document schemas, I have a \'timestamp\' field. The line for it in the schema is:

5条回答
  •  萌比男神i
    2020-12-15 21:30

    when you set mongoose type as "Date" , mongoose convert timestamp to UTC, because timestamp is a number, not a Date. then if you want to store timestamp, you should set mongoose type as "Number".

    myfield{
        type: Number,
        default: Date.now()
    }
    

提交回复
热议问题