Rename or Delete old and unused database collections

Currently it’s not possible to rename or delete database collections that are not required anymore . Its creating lot of confusion and clutter in the wix editor. So is there a simple way to delete /rename these unused database collections using wix code programmatically till a proper solution is released by wix team?

8 Likes

Hi,
Unfortunately, this is not available yet.
Feel free to add a feature request for this here: https://www.wix.com/code/home/forum/feature-requests

Thanks!
Liran.

The ability to rename objects is a basic development platform function. The inability to accommodate something simple like this makes me question whether wix code is useful for anything other than playing in the sandbox at this time. I certainly wouldn’t be using it for application development.

Sam, did you actually tried the product? We already see working sites with wixcode from our users
And, we’re still in beta phase - just tried to give you as much as possible as early as it’s possible

I started playing with this and the initial load got garbage on any special characters. I changed my .csv file format to utf-8 and it worked but now I have the initial table with 2000 records I don´t want… any chance to delete them at once instead one by one… I tried but didn´t find a way to delete the entire collection and load it again… than you!

Hi! the only way to delete items in collection not one by one - use code. You should add smth like this:

export function button8_click(event, $w) {
    wixData.query("NewCollectionName")
        .find()
        .then((result) => {
            for (var i = 0; i < result.items.length; i++){
                if (result.items[i] === null) continue;
                wixData.remove("NewCollectionName", result.items[i]._id);
            }
            console.log('erase done');
        });
}

This will erase everything from SnadBox collection, then you can override live collection with sandbox

I did as you suggested without success. Will try a little bit more before start erasing all those records one by one.
I created the button with the suggested code, but nothing happend.

Thanks

Juan.

Sorry, got to the computer only now.

So first - i missed part with importing wixData, you should import this module also like mentioned here:

add this at the beginning of the code:

 import wixData from 'wix-data'; 

Second, did you change name of the collection? Change “NewCollectionName” to your collection name

VOTE HERE PLEASE.

@Wixteam:
You guys really need to get ahead of this one before it gets messsssssssssssy in here like the old support/ticketing forum. By that I mean, CODE FEATURE REQUESTS need better organization/merging of duplicates and linking to them from other non-request responses related to the features in question directly so people can vote.

Thanks Mikhail. I figured out the import after reading the API documentation. With a little more of try & fail I figured out the given code erases 50 records at a time, to I kept pushing the button until the table got cleaned.

@Juan

Oh, i forget about it) There is a limit of 50 items which query shows at the moment (like “pages”)
you can also change it by setting this:

 wixData.query(" NewCollectionName ") 
      .limit(1000)
      .find()
      .then(......

Does that code work in the production collections or only sandbox - I got it to run in sandbox with no problem

It just depends on where you are while running it - if in preview, it will affect sandbox, if in live - live collection
Check permissions state first if it doesn’t work for you on live site…

Please add rename and delete database

Hey!

You can finally remove unneeded database collections from your site! No more “NewCollectionName”, “Test” or other typos polluting your database folder.


Be aware that removing your collection might have some consequences for your site, so it’s better to remove Dynamic Pages, Datasets, and Reference type fields that are pointing to collection about to be deleted.

More details here: https://support.wix.com/en/article/removing-a-collection-from-your-database . Happy cleaning!