Created
March 27, 2015 18:52
-
-
Save danared/f7ed8a8f3651e152478d to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/* | |
* Any schema with this plugin will run validators on | |
* `findOneAndUpdate()` by default. | |
*/ | |
var runValidatorsPlugin = function(schema, options) { | |
schema.pre('findOneAndUpdate', function(next) { | |
this.options.runValidators = true; | |
next(); | |
}); | |
}; | |
var breakfastSchema = new mongoose.Schema({ | |
steak: { | |
type: String, | |
required: true, | |
enum: ['flank', 'ribeye'], | |
}, | |
eggs: { | |
type: Number, | |
required: true, | |
min: 2 | |
} | |
}); | |
// Attach the plugin to `breakfastSchema` | |
breakfastSchema.plugin(runValidatorsPlugin); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment