Skip to content

Instantly share code, notes, and snippets.

@timhudson
Last active July 3, 2020 08:58
Show Gist options
  • Save timhudson/5951825 to your computer and use it in GitHub Desktop.
Save timhudson/5951825 to your computer and use it in GitHub Desktop.
Update the `lastUpdated` field every time a mongoose model is saved
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