Nodejs async mysql can insert only one record

  node.js, question

odiclipboard.png

As shown in the figure, I used the order of async, but findone and update are also asynchronous. if the code is written like this, I can only update one record. in fact, the length of rows should be 4

How to write it to ensure that every article is inserted

The callback function must be called after successful update, otherwise the next one 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 changed to something like this:

db.findOne({uuid: row.uuid}, function(err, doc) {
 if(err) {
 callback(err);
 } else {
 db.update(..., function(err, num) {
 console.log(err);
 callback(err);
 });
 bracket
 })

Refer to one of my related blogs:http://xxgblog.com/2015/12/22/nodejs-async-mysql/