Mongoose expand default validation

后端 未结 4 539
天涯浪人
天涯浪人 2021-01-06 17:49

I want to build \"minLength\" and \"maxLength\" in the mongoose schema validation rules, the current solution is:

var blogSchema = new Schema({
  title: { re         


        
4条回答
  •  死守一世寂寞
    2021-01-06 18:02

    Min and max have changed

    var breakfastSchema = new Schema({
      eggs: {
        type: Number,
        min: [6, 'Too few eggs'],
        max: 12
      },
      bacon: {
        type: Number,
        required: [true, 'Why no bacon?']
      },
      drink: {
        type: String,
        enum: ['Coffee', 'Tea'],
        required: function() {
          return this.bacon > 3;
        }
      }
    });
    

    https://mongoosejs.com/docs/validation.html

提交回复
热议问题