猫鼬验证

时间:2018-08-09 16:37:53

标签: mongodb mongoose

如何从模式中获得所有验证错误,而不仅是第一次发生?

const tshirtsSchema = new mongoose.Schema({
  title: {
    type: String,
    required: [true, 'T-shirt must have a title'],
    trim: true,
    minlength: 3,
    maxlength: 50,
  },
  price: {
    type: Number,
    min: [0, 'Price can not be less then 0'],
  },
  description: {
    type: String,
    minlength: 10,
    maxlength: 1000,
  }
})

当我发送空请求以将新数据保存到模型中时,我仅收到标题错误

ValidationError: tshirts validation failed: title: T-shirt must have a title

0 个答案:

没有答案