验证(validation)
Validation
var schema = new Schema({
name: {
type: String,
required: true
}
});
var Cat = db.model('Cat', schema);
// This cat has no name :(
var cat = new Cat();
cat.save(function(error) {
assert.equal(error.errors['name'].message,
'Path `name` is required.');
error = cat.validateSync();
assert.equal(error.errors['name'].message,
'Path `name` is required.');
});内置验证器
自定义验证器
异步的自定义验证器
验证错误
Required验证在嵌套的对象
更新(update)验证器
更新(update)验证器和this
context 选项
路径更新验证器 (Update Validator Paths)
更新指定的路径只运行验证器
(Update Validators Only Run On Specified Paths)
Last updated