-1
工作我更新從「開放」「Order.attempt_status」的文件,以「封閉」使用下面的代碼文件保存功能不是在貓鼬
AttemptSchema.pre('save', function (next) {
var attempt = this;
Order.findById(this.order).exec(function(err, order){
if(err) next(err);
if(!order) next(new Error('could not load order with order_id:' + this.order));
console.log(JSON.stringify(order));
order._doc.attempt_status = attempt.attempt_status;
console.log(JSON.stringify(order));
order.save(function(err){
if(err) next(err);
else next();
});
});
});
當我調試它看到attempt_status得到改變,但更新文件不保存在數據庫中。以下是調試屏幕。
點擊http://i.stack.imgur.com/ByCPT.png,如果圖像是可見的。控制檯打印是
{
"_id": "54a26634a4800130eb95be19",
"attempt_status": "open",
....
....
}
{
"_id": "54a26634a4800130eb95be19",
"attempt_status": "closed",
....
....
}
可以粘貼調試日誌作爲strings.cant查看圖像 – harryy000
什麼是最好的更新方式? – raju