[Mongoose] You Can Skip Validation with model.save({ validateBeforeSave: false })
Since Mongoose 4.2.0, the validateBeforeSave option has been added to skip validation when using model.save().
For sample code using the validateBeforeSave option, mongoose’s test code seemed intuitively understandable.
it('allows you to skip validation on save (gh-2981)', function(done) {
var db = start();
var MyModel = db.model('gh2981',
{name: {type: String, required: true}});
var doc = new MyModel();
doc.save({validateBeforeSave: false}, function(error) {
assert.ifError(error);
db.close(done);
});
});
Since this is only available from Mongoose 4.2.0, I recommend updating quickly if you’re using an older version.
That’s all from the Gemba.