Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

mongoose validate array of references required

const questionSchema = new mongoose.Schema({
  question: {
      type: String,
      required: [true, 'Question Required'],
      trim: true
  },
  options: {
    type: [{
        optionNo: Number,
        optionValue:{
            type: String,
            required: [true,'Option required'],
            trim: true
        }
    }],
    validate: [(val) -> val.length > 1, 'Must have minimum two options']
  }
});
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #mongoose #validate #array #references #required
ADD COMMENT
Topic
Name
1+8 =