Last active
July 3, 2020 08:58
-
-
Save timhudson/5951825 to your computer and use it in GitHub Desktop.
Update the `lastUpdated` field every time a mongoose model is saved
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var schema = mongoose.Schema({ | |
lastUpdated: {type: Date, 'default': Date.now} | |
}) | |
schema.pre('save', function(next) { | |
this.lastUpdated = Date.now() | |
next() | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment