What is the logical way?

//some predifined variables here......
// var ....

//CODE-START....
$w.onReady(async function () {
    settingsDATA = await wixData.query(SettingsDB).find()
    let dbLength = await settingsDATA.items.length
    console.log("DB-Length = ", dbLength)
    console.log(settingsDATA.items)

    if(dbLength===0) {console.log("if")
        save_Settings(0)
    }
    else{console.log("else")}
 })
function save_Settings (choice) {
  let toSave
    console.log(settingsDATA)
    console.log(DropDowns[0])
    console.log(DropDowns[1])
    console.log(DropDowns[2])

  if (choice===0){console.log("SAVE-DATABASE-ID")
        toSave = {
           "_id":          "00001",
           "title":        "General-Settings",
           "setup1":       DropDowns[0],
           "setup2":       DropDowns[1],
           "setup3":       DropDowns[2],
           "setup4":       DropDowns[3],
           "setup5":       DropDowns[4],
        }

        wixData.save(SettingsDB, toSave)
        .then( (results) => {
            let item = results;
            console.log(results)
        } )
        .catch((err) => {let errorMsg = err;} );
  }
}

When —> “save_Settings(0)” is deactivated…

 if(dbLength===0) {console.log("if")
        //save_Settings(0)
    }
    else{console.log("else")}

Everything works fine and i get the expected result.

But when turning-on the “save_Settings(0)”-function, something strange happens.
Then it seems that, the if-query is totaly ignored and the function starts immediately running.

Shouldn’t the length still be = 0 and why no console-log-info anymore —> (“if”)?
Database is at this moment still completely empty (live).

It jumps immediately to “else”, because the save-function does his job first (why ever).

Is this a logical behaviour, or do i have a brain-error?

You probably accidently added 1 record to your collection. Check it out.
(btw, it’s better to remove the second await, even though it’s harmless).

Thanks J.D. for your reply. In the meanwhile i found another solution for my problem.
Every efort to get it to work with “async-await” did not work. I also tried your suggestion. Perhaps the error was also caused by some other code-snipet, although i am sure, i have deactivated all the other codes, to figure out the problem.

I solved it by using —> then() and a changed code-structure. It works again, but my mission is still not complete :sweat_smile:

This is what i am working on…
https://www.media-junkie.com/pflegeservice

I am trying to generate a SUPER-FILTER-ENGINE :grin::sweat_smile::sweat_smile::sweat_smile: