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.
Notes:
- The
remove()
function 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(collectionId: string, itemId: string, [options: WixDataOptions]): Promise<Object>
remove Parameters
NAME
TYPE
DESCRIPTION
The ID of the collection to remove the item 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.
The ID of the item to remove.
An object containing options to use when processing this operation.
Returns
Fulfilled - The removed item, or null
if the item was not found.
Rejected - The error that caused the rejection.
Return Type:
Was this helpful?
1import wixData from 'wix-data';23// ...45wixData.remove("myCollection", "00001")6 .then((result) => {7 console.log(result); // see removed item below8 })9 .catch((err) => {10 console.log(err);11 });1213/* removed 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 */
1import wixData from 'wix-data';23// ...45let options = {6 "suppressAuth": true,7 "suppressHooks": true8};910wixData.remove("myCollection", "00001", options)11 .then((result) => {12 console.log(result); // see removed item below13 })14 .catch((err) => {15 console.log(err);16 });1718/* removed item is:19 *20 * {21 * "_id": "00001",22 * "_owner": "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb",23 * "_createdDate": "2017-05-24T12:33:18.938Z",24 * "_updatedDate": "2017-05-24T12:33:18.938Z",25 * "title": "Mr.",26 * "first_name": "John",27 * "last_name": "Doe"28 * }29 */
In this example, we demonstrate how you can you can build a CRUD "delete" function using remove()
. You can test out the code in our example template.
1import wixData from 'wix-data';23// Code for a delete operation using remove() //45function deleteGreeting(itemId) {6 return wixData.remove('Greetings', itemId);7}8