0
我有一个预先保存保存文档时定义的方法,具体如下:猫鼬仍然保存文档时出现错误
Org.pre("save",function(next, done) {
var Currency = require('./currency');
var cur = this.get('currency');
console.log("checking currency: " + cur);
Currency
.findOne({name: cur})
.select('-_id name')
.exec(function (err, currency) {
if (err) done(err);
if (!currency) done(new Error("The currency you selected ('" + currency + "') is not supported. Please select one from /currencies"));
next();
});
});
此方法检查货币收藏,看看货币字段输入支持的。在测试我的API时,我得到了相应的错误(500错误消息:您选择的货币...),但文档仍保存在MongoDB中。我期望在发送错误时不应该保存文档。我在这里错过了什么吗?
呀 - 愚蠢的错误。谢谢! –