【发布时间】:2017-06-04 23:30:18
【问题描述】:
没有调用回调,但它应该按照 mongoose 中间件中的记录:
schema.post('update', function(error, res, next) {
if (error.name === 'MongoError' && error.code === 11000) {
next(new Error('There was a duplicate key error'));
} else {
next(error);
}
});
我尝试了预更新,它可以工作:
schema.pre("update", function(next) {
console.warn('results', "i am called");
next(new Error("error line called"));
});
但我想要的是发布更新:
schema.post("update", function(error, res, next) {
console.warn('results', "is this called?");
});
实际模型更新:
MyModel.update({_id : 123}, req.payload, function (err, numberAffected, rawResponse) {
reply("done!");
});
我没有看到日志console.warn('results', "is this called?");,这是预期的吗?
附注: 机器:windows 10, 猫鼬版本:4.5.8
【问题讨论】:
标签: node.js mongoose mongoose-middleware