update( )


Developer Preview

This API is subject to change. Bug fixes and new features will be released based on developer feedback throughout the preview period.

Updates an item in a collection.

The update() method returns a Promise that resolves to the updated item from the specified collection. The Promise is rejected if the current user does not have update permissions for the collection.

Calling the update() method triggers the beforeUpdate() and afterUpdate() hooks if they have been defined.

The update() method compares the _id property of the specified item with the _id property values of the items in the specified collection. If an item in the collection has that _id value, update() replaces the item's property values with the ones in the specified item. If the existing item had properties with values and those properties were not included in the specified item, the values in those properties are lost. The item's _updatedDate property is also updated to the current date.

Any valid JavaScript object can be used as a property value. The update() method maintains the structure of the specified object. For example, objects that contain nested objects, arrays, or arrays with nested objects are all added to the collection as defined.

When updating an item in a collection that has a reference field, set the value of the reference field to the referenced item's _id value or the entire referenced item object.

The maximum size of an item that you can update in a collection is 500kb.

Notes:

  • The specified item must include an _id property that already exists in the collection.
  • The update() method does not support multi-reference fields. For multi-reference fields, use replaceReferences() or insertReference().
  • Translatable collections do not allow insertion and modification of items when working in a non-primary language. For example, if a collection's primary language is English, and the site visitor is viewing the site in French, calling update() fails and issues an error.
Permissions
Write Data Items
Learn more about app permissions.
Method Declaration
Copy
Method Parameters
dataCollectionIdstringRequired

ID of the collection item belongs to.


itemWixDataItemRequired

Data item to update.


optionsWixDataUpdateOptions

Options to use when processing this operation.

Returns
Return Type:Promise<WixDataItem>
Did this help?