Search.../

bulkRemove( )

Removes a number of items from a collection.

Description

The bulkRemove() function returns a Promise that resolves after the items have been removed from the specified collection. The Promise is rejected if the current user does not have delete permissions for the collection. If the delete permissions for the collection are set to Site member author, the only items that will be deleted are those for which the current user is the owner. All other items will be skipped.

Calling the bulkRemove() function triggers the beforeRemove() and afterRemove() hooks for each item that is deleted if the hooks have been defined.

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

Notes:

  • The bulkRemove() function also clears multiple-item reference fields for items in collections referenced by the specified items. For example, suppose you have a Movies collection with an Actors field that contains multiple references to items in a People collection. Removing items in the Movies collection also clears the data in the corresponding multiple-item reference fields in the People collection.
  • Bulk operations are limited to 1000 items per function call.

Syntax

function bulkRemove(collectionName: string, itemIds: Array<string>, [options: WixDataOptions]): Promise<WixDataBulkResult>

bulkRemove Parameters

NAME
TYPE
DESCRIPTION
collectionName

string

The name of the collection to remove the items from.

itemIds

Array<string>

IDs of the items to remove.

options
Optional

WixDataOptions

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

Returns

Fulfilled - The results of the bulk remove. Rejected - The error that caused the rejection.

Return Type:

Promise<WixDataBulkResult>

Was this helpful?

Remove multiple items from a collection

Code Example

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5let toRemove = ["00001", "00003", "00004"];
6
7wixData.bulkRemove("myCollection", toRemove)
8 .then( (results) => {
9 let removed = results.removed; // 2
10 let removedIds = results.removedItemIds; // see below
11 let skipped = results.skipped; // 0
12 } )
13 .catch( (err) => {
14 let errorMsg = err;
15 } );
16
17/* removedIds is:
18 *
19 * [
20 * "00001",
21 * "00002",
22 * "00003"
23 * ]
24 */
Remove multiple items from a collection using data options

Code Example

Copy Code
1import wixData from 'wix-data';
2
3// ...
4
5let toRemove = ["00001", "00003", "00004"];
6
7let options = {
8 "suppressAuth": true,
9 "suppressHooks": true
10};
11
12wixData.bulkRemove("myCollection", toRemove, options)
13 .then( (results) => {
14 let removed = results.removed; // 2
15 let removedIds = results.removedItemIds; // see below
16 let skipped = results.skipped; // 0
17 } )
18 .catch( (err) => {
19 let errorMsg = err;
20 } );
21
22/* removedIds is:
23 *
24 * [
25 * "00001",
26 * "00002",
27 * "00003"
28 * ]
29 */