All Row Delete in Collections

Hi All,

We’ve modified the all row delete code provided in

New code as follows (triggered after clicking button5);

export async function button5_click(event, $w) {
//Add your code for this event here:
var j;
var mygrp = 1000;
var totitems = await wixData.query(“CntrRetCollection”).count();
var noofloops = Math.ceil(totitems / mygrp);

for (j = 1; j<=noofloops; j++) {
const result = await wixData.query(“CntrRetCollection”).limit(1000).find();
// the next line will run only after the query has finished
for ( var i = 0; i < result.items.length; i++){
if (result.items[i] === null ) continue ;
await wixData.remove(“CntrRetCollection”, result.items[i]._id);
console.log(“Delete complete”);

Roughly half of the time - all 3000+ items are deleted without issue.

The rest of the time - deletion just stops at some random point i.e. sometimes only a few hundred items are deleted and other times only a few items remain and deletion process just stops.

Just wondering if anyone has any idea what may be causing this issue?


Check out this function:

export function cleanButtonOnClick(event, $w) {
    $w("#dynamicDataset").onReady(async() => {
    if ($w("#dynamicDataset").getCurrentItem()) {
    await $w("#dynamicDataset").remove();
    while ($w("#dynamicDataset").hasNext()) {
        await $w("#dynamicDataset").next();
        await $w("#dynamicDataset").remove();

Just connect the dataset to the wanted collection.

Hi Roi - thanks for the suggestion. Actually the code works but only roughly half of the time. We’ve also tried Yisrael’s suggested database query method verbatim from with same result so wondering if cause could be something else rather than a coding issue.

Hi Oalbps and Roi,

I have the very same issue. When I try to remove even 90 records the routine will leave about 5-10 records that should have been removed. I also used the function that Yisrael posted. I have tried running it in the backend as well as in page code and there is more consistency from the backend than from page code, but, still inconsistent for real world use.

This is a major issue!! The integrity of the data will be compromised greatly if these random results keep happening. have you guys had any luck understanding what’s going on here?