# removeAll() function in wixData please

**URL:** <https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649>\
**Category:** Ask the community\
**Tags:** code\
**Created:** [November 8, 2018, 2:11pm UTC](https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649 "2018-11-08T14:11:57Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![andreas-kviby](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/andreas-kviby/32/790_2.png) [@andreas-kviby](https://forum.wixstudio.com/u/andreas-kviby)\
**Post date:** [November 8, 2018, 2:11pm UTC](https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649/1 "2018-11-08T14:11:57Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [November 8, 2018, 2:22pm UTC](https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649/2 "2018-11-08T14:22:34Z")

</div>

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?” 🙃

---

<div class="post-metadata">

**Author:** ![code-queen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-queen/32/696_2.png) [@code-queen](https://forum.wixstudio.com/u/code-queen)\
**Post date:** [November 8, 2018, 2:40pm UTC](https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649/3 "2018-11-08T14:40:53Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [November 8, 2018, 2:42pm UTC](https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649/4 "2018-11-08T14:42:31Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andreas-kviby](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/andreas-kviby/32/790_2.png) [@andreas-kviby](https://forum.wixstudio.com/u/andreas-kviby)\
**Post date:** [November 8, 2018, 2:50pm UTC](https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649/5 "2018-11-08T14:50:00Z")

</div>

@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 🙂

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [November 8, 2018, 2:51pm UTC](https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649/6 "2018-11-08T14:51:23Z")

</div>

@andreas-kviby😂

---

<div class="post-metadata">

**Author:** ![code-queen](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/code-queen/32/696_2.png) [@code-queen](https://forum.wixstudio.com/u/code-queen)\
**Post date:** [November 8, 2018, 2:59pm UTC](https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649/7 "2018-11-08T14:59:14Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![andreas-kviby](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/andreas-kviby/32/790_2.png) [@andreas-kviby](https://forum.wixstudio.com/u/andreas-kviby)\
**Post date:** [November 8, 2018, 3:10pm UTC](https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649/8 "2018-11-08T15:10:17Z")

</div>

@code-queen

![](https://us1.discourse-cdn.com/wix/original/3X/0/b/0b23c75fbfabd4e1e1b91943d7de3c9a9886ba48.png)

---

<div class="post-metadata">

**Author:** ![mikemoynihan99](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/mikemoynihan99/32/5930_2.png) [@mikemoynihan99](https://forum.wixstudio.com/u/mikemoynihan99)\
**Post date:** [November 9, 2018, 6:04pm UTC](https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649/9 "2018-11-09T18:04:33Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![spivey](https://avatars.discourse-cdn.com/v4/letter/s/bb73d2/32.png) [@spivey](https://forum.wixstudio.com/u/spivey)\
**Post date:** [November 20, 2018, 5:11pm UTC](https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649/10 "2018-11-20T17:11:09Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![yisrael-wix](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/yisrael-wix/32/1107_2.png) [@yisrael-wix](https://forum.wixstudio.com/u/yisrael-wix)\
**Post date:** [November 21, 2018, 5:46am UTC](https://forum.wixstudio.com/t/removeall-function-in-wixdata-please/14649/11 "2018-11-21T05:46:49Z")

</div>

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