I have been trying to solve this problem for 2 days. I really need help from any of you! Please!!!
I need to delete some items from my collection frequently before I replace them (about 800 each time).
I tried with remove () but it fails very often and no deletes all the records I need.
So I’m tying to use bulkRemove() . In the examples of Corvid the items to remove are defined in the variable toRemove.
How I could define this variable with the result of a query that retrieve the _id that I need to delete form my Collection? Or what is the best method to do this?
This is the code I Have but I know it doesn’t work:
function deleteTiempos() {
console.log( “10.1 Inicia deleteTiempos” )
let AnoSel = $w( ‘#inpAno’ ).value;
let MesSel = $w( ‘#inpMesNo’ ).value;
wixData.query( “Tiempos” )
.limit( 1000 )
.eq( “mes” ,MesSel)
.find()
.then( (results) => {
if (results.items.length > 0 ) {
let toDeleteArray = ;
for ( var i = 0 ; i < results.items.length; i++)
{
let toRemove = { “_id” : results.items[i]._id};
toDeleteArray.push(Object.assign( toRemove)); //I get a JSON Array
} //end of loop
wixData.bulkRemove( "Tiempos" , toDeleteArray) //I need a bracket Array
.then( (results2) => {
let removed = results2.removed;
console.log( "removed " + removed)
} )
. catch ( (err) => {
let errorMsg = err;
} )
} **else** {
// handle case where no matching items found
}
} )
. catch ( (err) => {
let errorMsg = err;
} )
}
WIX experts also propose the folowing method, using datasets, but is very, very slow! It takes > 40 min and with other languages it is <1 sec!
exportfunction button1_click(event, $w) {
let dataset = $w(" #dataset1 "); // or whatever name for your dataset if different dataset.onReady( async () => {
while (dataset.getCurrentItem()) {
console.log(‘x’);
await dataset.remove();
}
});
dataset.refresh(); }