Skip to content

Instantly share code, notes, and snippets.

@Lazhari
Created July 20, 2015 01:29
Show Gist options
  • Save Lazhari/03731ddbfff06adc8172 to your computer and use it in GitHub Desktop.
Save Lazhari/03731ddbfff06adc8172 to your computer and use it in GitHub Desktop.
Sample mongoose plugin
module.exports = exports = function mongoosePluginRestaurant (schema, options) {
schema.pre('save', function (next) {
if (this.isModified('description')) {
this.descriptionUpdated = new Date;
}
if(this.isModified())
this.updated = new Date;
next()
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment