在嵌入式阵列上的猫鼬条件式必需字段验证不起作用。 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;
}
}
}
]
}
});