【发布时间】:2016-11-02 04:32:18
【问题描述】:
我正在使用猫鼬。因此,在我的一个模式中,我只想在特定字段满足条件时才将必填字段设置为 true。因此,我编写了一个函数,仅当条件为真时才将必填字段设置为真。但是即使条件错误,所需的标志也为真。甚至函数内部的控制台也没有被执行。我究竟做错了什么?提前致谢
这是我的架构
var ApplicationsSchema = new Schema({
first_name: {
type: String,
required: function(value) {
console.log('inside function')
console.log(this.status)
return this.status === 'submit';
},
validate: [validateLocalStrategyProperty, 'Please fill in the name of the Organization']
},
last_name: {
type: String,
validate: [validateLocalStrategyProperty, 'Please fill in the name of the Organization']
},
phone_number: {
type: String,
validate: [validateLocalStrategyProperty, 'Please fill in the phone number']
},
status:{
type: String,
}
});
mongoose.model('Applications', ApplicationsSchema);
【问题讨论】: