removeAll() function in wixData please

Sometime you develop stuff or everyday, then you want to make a clean start and to delete all records in a Data Collection requires you to loop through records to remove them. This triggers timeouts when there is a lot of records.

  1. Add a function removeAll() to the wixData library.

  2. Or just make a new right click command, “Remove all items” from Data Collection

1 Like

Hey Andreas, I thought we were friends. Just imagine if Wix users started doing deleteAll(). And then imagine all the tech support requests and forum posts saying “Please help, I accidentally deleted my entire database. How can I restore it?” :upside_down_face:

I just had this vision in my head and my head hurt lol

See @andreas-kviby , @code-queen is a good friend.

@yisrael-wix I am a true friend and rely on saying “My bad” or “Fxck me” when that happens because it happens in all programming environments but you are correct. I am rather a friend of yours than having the deleteAll() feature. Delete me or the post? The post please :slight_smile:

@andreas-kviby :joy:

@andreas-kviby lol — we need some emoji icons … the little heart isn’t cutting it

@code-queen

Can be done with code, below are 2 different methods. Create a new page on your site, place a button on the page and execute the below code with an onClick event. For Method 2 you also need top add a Dataset to the page.

Method 1:


import wixData from ‘wix-data’;

export function button1_click(event, $w) {
wixData.query(“database”) //enter collection name here
.limit(1000)
.find()
.then((result) => {
for ( var i = 0; i < result.items.length; i++) {
if (result.items[i] === null ) continue ;
wixData.remove(“database”, result.items[i]._id); //enter collection name here
}
console.log(‘erase done’);
});
}

Method 2:


export function 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();
}

How about an option to overwrite all on import? Not providing this functionality because you are afraid someone might misuse it makes it miserable for those that NEED this functionality. I have had no luck gettting the scripts below working.

@spivey I use these scripts all the time and they work just fine. What is happening for you?