Update an existing row in DB in new data

Dear Ysrael, Thank You very much!
Can You help me find answer one one important question.

I try solve one problem during week or more and cannot.
I write code use Your example and it work
but when I try update my database in FOR loop
with big amount of Rows - some of this rows lost…

If I update 10 rows - It’s working
If I manually change index in FOR statements (0-10, next 11-20, next 21- 30…)
Finally Database records updated completely, but if I run "FOR from 0 to 90 -
30% of records (rows) not updated… lost (stay in previous data state)

I guess that problem with time responding database and I errors happened when I try to write until database ready, but I cannot find answer nowhere… How be sure that database ready again

AND

I read Your another advice from June 2019
And I understand в that mistakes happened because Database not ready when I make to much requests
But

  1. How I put my ONCLICK Button external function inside Onready?
    It’s impossible

  2. When I put database Refresh inside ONREADY some Table wit my datasate Refreshed on screen. (this result - obviously)

I will be appreciate any help…
Thank You in advance.
Sincerely, Misha

Here code fragment…
in FOR loop i put index values 70 - 81
to show that with small amount of - update working.
If I put 0-91 - 30% of records - not updated


export function button3_click(event) {

let i = 0;
let recid = 1;

  wixData.query("dbBardSongs") 
       .eq("bardName", selectedKey) 
       .limit(130) 
       .find() 
       .then( (results1) => { 

for (i=90; i<98; i++) {
recid = results1.items[i]._id;
onerecord2(i, recid);
}

  }) 
  . **catch** ((err) => { 

//let errorMsg = err;
console.log("Error in Query = ");
console.log(err);
});
}

export function onerecord2 (index, recid) {
let i = index;
wixData.get(“dbBardSongs”, recid)
.then((toUpdate) => {
toUpdate.orderNumber = (i + 1);
wixData.update(“dbBardSongs”, toUpdate)
.then((result) => {
})
. catch ((err) => {
//let errorMsg = err;
console.log("Eror in Update = ");
console.log(err);
});
})
. catch ((err) => {
//let errorMsg = err;
console.log("Error with Get = ");
console.log(err);
});

}

Almost All Error I receive in CATCH “Error in Get” but No CODE of Error - Just word “Error”