稍微调整一下架构设置,即可添加验证选项:
var peopleSchema = new Schema({ name: { type: String, required: true, default: true }, friends: { type: [{ type: Schema.Types.ObjectId, ref: 'peopleModel' }], validate: [arrayLimit, '{PATH} exceeds the limit of 10'] }});function arrayLimit(val) { return val.length <= 10;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)