0

I want to save UTC date at mongodb after executing an API.
For example, the code below at mongoose makes UTC date automatically with default option. and The saving result is '2019-05-05 02:06:03.797Z'.

 createdAt: {
    type: Date,
    default: Date.now,
  },


And the mongoose schema has a variable as the type of Date.
And I want to put the date like 'default:Date.now' for saving UTC after executing an API with same format.

recentAccess: Date,

Could you help me some advice?

Bharti Rawat
  • 1,949
  • 21
  • 32
DD DD
  • 1,148
  • 1
  • 10
  • 33
  • 1
    Mongodb by default saves time in UTC. You do not need to worry about that. – Ashh May 31 '19 at 05:11
  • But how can I update default Date.now at mongodb? I m thinking it needs using insert Date inside of 'recentAccess' after every running of a specificg API. – DD DD May 31 '19 at 05:18
  • 1
    Allow option for [`timestamp`](https://stackoverflow.com/questions/12669615/add-created-at-and-updated-at-fields-to-mongoose-schemas). It will always give you `updatedAt` field when ever document will update. – Ashh May 31 '19 at 05:22

0 Answers0