我想在猫鼬模式验证规则中构建“minLength”和“maxLength”,目前的解决方案是:
var blogSchema = new Schema({
title: { required: true, type: String }
});
blogSchema.path('title').validate(function(value) {
if (value.length < 8 || value.length > 32) return next(new Error('length'));
});
但是我认为这应该通过添加自定义模式规则来简化,如下所示:
var blogSchema = new Schema({
title: {
type: String,
required: true,
minLength: 8,
maxLength: 32
}
});
我该怎么做,这甚至可能吗?