Please how do I get this code to work?

async function retrieveAllItemsx() {  
let allItemsx= [];
let hasNextx = true;
let countx = 0
while(hasNextx){
    let resultx = await wixData.query("WEEKERS")
   .isNotEmpty("_id")
    .limit(1000)
    .skip(countx)
    .find();
    countx += resultx.items.length;
    hasNextx = resultx.hasNext();
    allItemsx.push(resultx.items)   
}
return allItemsx[0]
}
(async () => {

let allItemex9 = await retrieveAllItemsx()
console.log("ALL ITEMS ARE",allItemex9)
let updating={//update 
 "name":"totalEntries",
// "total":(allItemex9.length).toString(),
 "total":(x).toString(),

}
     
          wixData.save("APTOTAL", updating)
        .then((result) => {
          let item = result; //see item below
        })

 .catch((err) => {
 let errorMsg = err;
            });
})

I am trying to get all the items from a database and count them and save, but it is not working. Also if a dataset is connected to a database with 10k items, does the .getTotalCount() return the 10k number or are there limits?