Delet All Entires in Database

Hello,
Any suggestions on how I can delete all entries in a database? I have tried selecting all and deleting with no avail and need help. Thanks!

Open your collection in your database manager. On the furthest left column in the collection left mouse click on the number “1” and hold the left mouse button down. While holding the left mouse button down use the middle wheel on the mouse to scroll down though your collection. Once you have selected all the rows you want to delete right mouse click on whatever number is displayed on the furthest left column in the collection and select delete.

However for very large databases should be done with code for efficiency, 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.

Open your live site to delete all items in your live collection/database or open your site in the editor pre-view mode to delete all items in your sandbox.

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