Transferring data from one collection to another

Hi Bruno,

Sorry to bother you with this again, but when I run your code, it copies some number of records to the new collection, but a different amount every time I run it, and never even close to the total number I need copied. I created a shorter source collection of about 350 items, and I get somewhere between 70 and 150 copied each time I run it. Is this possible a timing problem? Again, I appreciate your help.

Here’s the code I’m running.

export const copyRowsCount = async () => {

let query = await wixData . query ( ‘SmallBookList’ ). limit ( 1000 ). find ()

let allItems = query . items
if ( allItems . length > 0 ) {
while ( query . hasNext ()) {
query = await query . next ()
allItems = [… allItems , … query . items ]
}
} // This is going to retrieve all the items from the Source collection.

console . log ( allItems );
console . log ( allItems . length );

let cnt = 0 ;
let results =
allItems . forEach (( item ) => {
cnt ++;
$w ( ‘#txtRecordNum’ ). text = String ( cnt );
//console.log(item);
for ( let i = 0 ; i < item . copies ; i ++) {
results . push ( wixData . insert ( ‘ISBN’ , { title : item . title , isbn : item . isbn }))
//console.log(item);
}

}) //This is going to select the items to be added.
await Promise . all ( results )

}