How do I update a property with the current date in a Mongoose schema on every save?


Question

In my database collections, I want to update a 'lastChanged' field every time the record is updated with the current datetime. I want it to be in the same format as mongoose's default date like:

ISODate("2011-10-06T14: 01: 31.106Z")

Any words of wisdom?

1
14
9/22/2017 6:01:22 PM

If you just want an ISO String use:

new Date().toISOString()
17
1/29/2012 8:51:32 PM

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow
Icon