Created
March 27, 2015 18:46
-
-
Save danared/3b8be3d2e3cfc962a75a 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
var breakfastSchema = new mongoose.Schema({ | |
steak: { | |
type: String, | |
required: true, | |
enum: ['flank', 'ribeye'], | |
validate: function(v) { | |
// Woops! `this` is equal to the global object! | |
if (this.eggs >= 4) { | |
return v === 'flank'; | |
} | |
} | |
}, | |
eggs: { | |
type: Number, | |
required: true, | |
min: 2 | |
} | |
}); | |
var Breakfast = mongoose.model('breakfast', breakfastSchema, 'breakfasts'); | |
var updates = { $set: { steak: 'ribeye', eggs: 4 } }; | |
Breakfast.findOneAndUpdate({}, updates, { runValidators: true }, function(err) { | |
// No err! | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment