嵌入式阵列上的猫鼬条件必填字段验证

时间:2019-05-07 15:24:23

标签: mongodb mongoose mongoose-schema

在嵌入式阵列上的猫鼬条件式必需字段验证不起作用。 this.currently_studying属性在检查时返回未定义。

  mongoose.Schema({
    user_id: {
        type: mongoose.Schema.Types.ObjectId,
        ref: 'User'
    },
    educations: {
        type: [
            {
                university: {
                    type : String,
                    required: true
                },
                currently_studying: {
                    type: Boolean,
                    default: false
                },
                start_date: {
                    type: Date,
                    required: true
                },
                end_date: {
                    type: Date,
                    required: function(data){
                        console.log(this.currently_studying);
                        return !this.currently_studying; 
                    }
                }
            }
        ]
    }
});

0 个答案:

没有答案