📜  mongoose 验证所需的引用数组 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:03:14.293000             🧑  作者: Mango

代码示例2
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']
  }
});