Please increase your query limit, please

Hi Ahmad,
We followed this approach with the Variants table of WiX Stores. We have 37.000 rows in the concerning project. Your code works, but the while…hasNext() construct runs in an endless loop. To examine it, we stored the retrieved results in a table (with bulkInsert) and saw that the code duplicated all rows. We aborted the loop to get to an end, but it doesn’t stop running on the backend and produces over 700.000 entries (instead of 37.000).

Any ideas?

Regards,
Tom (dMorpheus)

This is our code:

export async function transferVariants ( rowsCount ) {

**return**  wixData . query ( 'Stores/Variants' ) 

    // fetch first items. 100 is the limit for variants. 
    . limit ( 100 )  
    . find () 
    . then ( **async**  ( result ) => { 
        
        // Init result count 
        **let**  resultCount  =  result . length ; 

        // Display total count of variants (36.228) 
        console . log ( "total count: "  +  result . totalCount ); 

        // Store first items 
        storeVariants ( result ); 

        // Fetch and store all remaining results 
        **while**  ( result . hasNext ()) { 
            // fetch next items 
            
            // V1: Delivers right results, but causes error after 10.000 rows. Error: WDE:0053, WDE:0054 
            //result = await result.next()                       
            
            // V2: produces a lot of duplicates 
            **const**  nextResult  =  **await**  result . next ()               
            **const**  itemsCount  =  **await**  storeVariants ( nextResult ); 
            
            // Log results 
            resultCount  =  resultCount  +  itemsCount ; 
            console . log ( resultCount  +  " variants processed" ) 
        } 

        **return**  0 ; 
    }) 

    // Handle error 
    . **catch** (( error ) => { 
        console . error ( error ); 
        **return**  - 1 ; 
    }); 

}

export async function storeVariants ( variants ) {

**let**  allVariants  = []; 

// Extract subset of data for target table (as array of objects) 
variants . items . forEach ( variant  => { 
    **let**  toInsert  = { 
        'var_title' :  variant . variantName , 
        'prod_title' :  variant . productName , 
        'prod_variant' :  variant . _id , 
    } 
    allVariants . push ( toInsert ); 
}); 

// Insert object array in target table 
**return**  wixData . bulkInsert ( "variants_configurator" ,  allVariants ) 

    . then (() => { 
        //console.log(allVariants.length + " variants stored"); 
        **return**  allVariants . length 
    }) 

    . **catch** (( error ) => { 
        console . error ( error ); 
        **return**  - 1 ; 
    }) 

}