wixData.Update doest work

trying to get a value of a field “total” in “total” collection
do calculation
and then update it back
(simple)
code:
wixData.query(‘total’).eq(‘kasar’,1).find()
.then(results =>{
if (results.items.length > 0) {
var tot = results.items[0];
console.log("total is " + tot.total );
let met = exChange*Number(amount)/3600;
let stam =Number(Math.round(met+‘e2’)+‘e-2’);
tot.total = tot.total + stam;
console.log("update total new value "+ tot.total);
debugger ;
wixData.update(“total”,tot)}})
wixData.query(‘total’).eq(‘kasar’,1).find()
.then(results =>{
if (results.items.length > 0) {
var tot1 = results.items[0];
console.log("total after update is " + tot1.total)}

debugger ;
console output shows no update was done
total is 44.24
update total new value 45.04
total after update is 44.24
and there is an error
“Uncaught (in promise)”
whats wrong?

This issue has come up on another forum(actually, with .save and a query afterwards, but it´s the same issue). In your code, basically, you should do 2 things:

  1. wait for the .update to return its Promise (I would suggest using async/await, it leaves cleaner code)
  2. put a timeout (around 500 to 1000 msecs between the update and the next query. Then it will work. Good luck.

EDIT: also, it is recommended to not do a query directly after a .save/.update, but use the returned values from the promise after those actions.That will hold 45.04.