Search.../

remove( )

Removes an item from a collection.

Description

The remove() function returns a Promise that resolves to the removed item after it has been removed from the specified collection. The Promise is rejected if the current user does not have delete permissions for the collection.

Calling the remove() function triggers the beforeRemove() and afterRemove() hooks if they have been defined.

Use the options parameter to run remove() from backend code without checking for permissions or without its registered hooks.

Note: remove() also clears multiple-item reference fields for items in collections referenced by the specified item. For example, suppose you have a Movies collection with an Actors field that contains multiple references to items in a People collection. Removing an item in the Movies collection also clears the data in the corresponding multiple-item reference fields in the People collection.

Syntax

function remove(collectionName: string, itemId: string, [options: WixDataOptions]): Promise<Object>

remove Parameters

NAME
TYPE
DESCRIPTION
collectionName

string

The collection to remove the item from.

itemId

string

The ID of the item to remove.

options
Optional

WixDataOptions

An object with one or both of the following boolean properties: suppressAuth, suppressHooks.

Returns

Fulfilled - The removed item. Rejected - The error that caused the rejection.

Return Type:

Promise<Object>

Was this helpful?

Remove an item from a collection

Code Example

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5wixData.remove("myCollection", "00001")
6 .then( (results) => {
7 let item = results; //see item below
8 } )
9 .catch( (err) => {
10 let errorMsg = err;
11 } );
12
13/* item is:
14 *
15 * {
16 * "_id": "00001",
17 * "_owner": "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb",
18 * "_createdDate": "2017-05-24T12:33:18.938Z",
19 * "_updatedDate": "2017-05-24T12:33:18.938Z",
20 * "title": "Mr.",
21 * "first_name": "John",
22 * "last_name": "Doe"
23 * }
24 */
Remove an item from a collection using data options

Code Example

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5let options = {
6 "suppressAuth": true,
7 "suppressHooks": true
8};
9
10wixData.remove("myCollection", "00001", options)
11 .then( (results) => {
12 if(results.items.length > 0) {
13 let firstItem = results.items[0]; //see item below
14 } else {
15 // handle case where no matching items found
16 }
17 } )
18 .catch( (err) => {
19 let errorMsg = err;
20 } );
21
22/* item is:
23 *
24 * {
25 * "_id": "00001",
26 * "_owner": "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb",
27 * "_createdDate": "2017-05-24T12:33:18.938Z",
28 * "_updatedDate": "2017-05-24T12:33:18.938Z",
29 * "title": "Mr.",
30 * "first_name": "John",
31 * "last_name": "Doe"
32 * }
33 */