为什么以下代码导致Mongoose save
失败?如果我删除validate: utils.uuid.isValid
(返回布尔值),则该过程将完成:
var accountSchema = new mongoose.Schema({
_id : { type: String, default: utils.uuid.init, validate: utils.uuid.isValid },
n : { type: String }, // Display Name
ac : { type: Date },
au : { type: Date },
ad : { type: Date },
am : { type: String }
});
另外,如果我删除字段的validate
属性,并尝试在pre('validate', cb)
或pre('save', cb)
调用中设置值,则会产生相同的结果:
accountSchema.pre('validate', function(next) {
var now = new Date(),
memberId = this.am;
console.log('In Account validate (member : ' + memberId + ')');
if (this.isNew) { this.ac = now; console.log('Item is new.'); }
else if (this.isModified()) { this.au = now; console.log('Item is modified.'); }
else { return next();
console.log('Canceling Account validate.');
}
console.log(JSON.stringify(this));
console.log('Completed Account validate.');
next();
});
什么都没有崩溃。在Webstorm中,处理只是停止,并显示消息“Process finished with exit code 139”。