Search.../

deleteDataCollection( )

Deletes a data collection.

Description

Note: Once a collection is deleted, it can't be restored.

Admin Method

This function requires elevated permissions to run. This function is not universal and runs only on the backend.

Syntax

function deleteDataCollection(dataCollectionId: string): Promise<void>

deleteDataCollection Parameters

NAME
TYPE
DESCRIPTION
dataCollectionId
string

ID of the collection to delete.

Returns

Return Type:

Promise<
void
>

Was this helpful?

Delete an existing collection (dashboard page code)

Copy Code
1import { collections } from "wix-data.v2";
2
3// Deleting the collection whose _id is "myMusicCollection":
4// const dataCollectionId = "myMusicCollection"
5
6export async function myDeleteDataCollectionFunction(dataCollectionId) {
7 try {
8 await collections.deleteDataCollection(dataCollectionId);
9 return;
10 } catch (error) {
11 console.error(error);
12 // Handle the error
13 }
14}
15
16/* Promise resolves to void */
Delete an existing collection (export from backend code)

Copy Code
1import { Permissions, webMethod } from 'wix-web-module';
2import { collections } from 'wix-data.v2';
3
4// Deleting the collection whose _id is "myMusicCollection":
5// const dataCollectionId = "myMusicCollection"
6
7export const myDeleteDataCollectionFunction = webMethod(Permissions.Anyone, async (dataCollectionId) => {
8 try {
9 await collections.deleteDataCollection(dataCollectionId);
10 return;
11 } catch (error) {
12 console.error(error);
13 // Handle the error
14 }
15});
16
17/* Promise resolves to void */
18