Nodejs async mysql can insert only one record

  node.js, question


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) {
 } else {
 db.update(..., function(err, num) {

Refer to one of my related blogs: