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(collectionId: string, itemIds: Array<string>, [options: WixDataOptions]): Promise<WixDataBulkRemoveResult>

bulkRemove Parameters

NAME
TYPE
DESCRIPTION
collectionId
string

The ID of the collection to remove the items from.

To find your collectionId, select the Databases tab in the Velo Sidebar. Hover over your collection, click the three dots, and select Edit Settings.

itemIds
Array<string>

IDs of the items to remove.

The array must contain at least one item. Passing an empty array returns an error.

options
Optional
WixDataOptions

An object containing options to use when processing this operation.

Returns

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

Return Type:

Promise<WixDataBulkRemoveResult>
NAME
TYPE
DESCRIPTION
removed
number

The number of removed items.

skipped
number

The number of skipped items.

removedItemIds
Array<string>

List of IDs of removed items.

errors
Array<Error>

List of errors.

Was this helpful?

Remove multiple items from a collection

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

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 */