odi
如图,我用了async的顺序执行,但是findone 和update 也是异步的,代码这样写的话,我只能更新一条记录,其实应该更新条的,rows的长度是4
怎么写才能保证每条都插入呢
业精于勤,荒于嬉;行成于思,毁于随。
Be sure to call the callback function after executing a successful update, otherwise the next item in the rows array will not be executed. In addition, whether findOne or update fails, that is, there is err, then callback (err) must be executed.
The code should almost change to this:
db.findOne({uuid: row.uuid}, function(err, doc) { if(err) { callback(err); } else { db.update(..., function(err, num) { console.log(err); callback(err); }); } })
Refer to a related blog of mine: http://xxgblog.com/2015/12/22/nodejs-async-mysql/
Be sure to call the callback function after executing a successful update, otherwise the next item in the rows array will not be executed.
In addition, whether findOne or update fails, that is, there is err, then callback (err) must be executed.
The code should almost change to this:
Refer to a related blog of mine: http://xxgblog.com/2015/12/22/nodejs-async-mysql/