int
我的验证功能不起作用。如何验证我的状态字符串数组。我想验证每个 20 个字符的字符串
答案 0 :(得分:0)
你可以这样试试:
const postschema = new Schema({
userName :{
type : String,
required : true
},
status: {
type: [{
type: Schema.Types.ObjectId,
ref: 'peopleModel'
}],
validate: [arrayLimit, '{PATH} exceeds the limit of 10']
}
});
function arrayLimit(val) {
return val.length <= 10;
}