Query with more than 1.000 records with "do while"

hello, i try this code but give me the error “Error”, how i can fix it?
If i remove the do while all works.

export function getFeedGoogle() {
    let listing = [];
    return wixData.query("ProdottiEspansi")
    .limit(100)
    .isNotEmpty("prodotto")
    .include("prodotto")
    .find()
    .then( (resultsProdottiEspansi) => {
        do {
            if(resultsProdottiEspansi.items.length > 0) {
                for(let i = 0; i < resultsProdottiEspansi.items.length; i++) {
                    let item = resultsProdottiEspansi.items[i]
                        listing.push({
                            "id": item.prodotto.sku,
                              ......... 
                            });
                    resultsProdottiEspansi.next()
                }
            }
        } while (resultsProdottiEspansi.hasNext());
            return js2xml({"item": listing} , { compact: true });
    } )
    .catch((err) => {
        console.log(err)
        console.log(err.message)
    });
}


this is the error.

It’s not so easy to understand what you’re trying to do.
If all you want is to get all the records (over 1k), try to do something like:

function getAllItems(){
    return query.limit(1000).find()
    .then(async res => {
        let items = res.items;
         while (res.hasNext()) {
            res = await res.next();
            items = items.concat(res.items);
        }
        return items;
    })
    .catch(err => err)
}

i’m trying to create Google Shopping Feed, i have a dataset with a row for each product in store (with a related field call “prodotto”) where i add the other information required by google (such as google_product_cathegory, size, … etc).
I need to parse all products to create the XML Feed, I have an other http function accessible from link https://<domain.it>/_functions/feed_google to get the public XML feed

I try your code but not works. This is the complete code:

import {js2xml} from 'xml-js';
import wixData from 'wix-data';


export function getFeedGoogle() {
    let listing = [];
    let allProducts=getAllItems();
    console.log("----------LOG 0");
    console.log(allProducts);
            if(allProducts[0] > 0) {
                for(let i = 0; i < allProducts[0] ; i++) { //i have to use array with products and size because allProducts.lenght not works  
                    let item = allProducts[1][i]
                    let disponibilita="out_of_stock"
                    if (item.prodotto.inStock)
                         disponibilita="in_stock"
                    let spedizione="";
                    if (item.prodotto.discountedPrice<30)
                         spedizione="IT:::10.00";
                    listing.push({
                            "g:id": item.prodotto.sku,
                            "g:availability": disponibilita,
                            "g:price": String(item.prodotto.price.toFixed(2)) + " EUR",
                            "g:title": item.prodotto.name,
                            "g:description":"<![CDATA["+item.prodotto.description.replace(/(<([^>]+)>)/ig, "").replace(/(&rsquo;)/ig, "'").replace(/\r?\n/g,"")+"]]>",
                            "g:link": "https://www.comete.it"+item.prodotto.productPageUrl,
                            "g:condition":"new",
                            "g:image_link": getFullImageURL(item.prodotto.mainMedia),
                            "g:brand": "Comete Gioielli",
                            "g:sale_price": String(item.prodotto.discountedPrice.toFixed(2)) + " EUR",
                            "g:shipping": spedizione,
                            "g:google_product_category":item.categoriaProdottiGoogle,
                            "g:custom_label_4":"<![CDATA["+ item.etichettaPersonalizzata4+"]]>",
                            "g:gender":item.gender,
                            "g:material":"<![CDATA["+item.material+"]]>",
                            "g:product_type":"<![CDATA["+item.productType+"]]>"
                    });
                     console.log("----------LOG 1 "+i);
                }
                console.log("----------LOG 2");
            }
            console.log("----------PRODUCT LIST:");
            console.log(listing);
            return js2xml({"item": listing} , { compact: true });
}

function getAllItems(){
    return wixData.query("ProdottiEspansi")
    .limit(1000)
    .isNotEmpty("prodotto")
    .include("prodotto")
    .find()
    .then(async res => {
        let size=res.length;
        let items = res.items; //i need the total size
         while (res.hasNext()) {
            res = await res.next();
            size+=res.length;
            items = items.concat(res.items);
        }
        return [size, items]; 
    })
    .catch(err => err)
}


 function getFullImageURL(imageSRC) {
 let strReturnImage = "";
 if (imageSRC.startsWith("wix:image:")) {
 let wixImageURL = "";
        wixImageURL = "https://static.wixstatic.com/media/";
 let wixLocalURL = "";
        wixLocalURL = imageSRC.replace('wix:image://v1/', '');
        wixLocalURL = wixLocalURL.substr(0, wixLocalURL.lastIndexOf('/'));
        strReturnImage = wixImageURL + wixLocalURL;
    } else {
        strReturnImage = imageSRC;
    }
 return strReturnImage;
}

But not works: this is the result:

Has you see your code (getAllItems) not work because return an empty array

I i use my older function whiteout the do-while return correct the xml array with 100 products. If i try to get more records not works.

can you suggest something?