bulkSave( )


Inserts or updates a number of items in a collection.

The bulkSave() function returns a Promise that resolves after the items have been added or updated in the specified collection. The Promise is rejected if the current user does not have the necessary permissions for the collection.

The bulkSave() function inserts or updates the specified items, depending on whether they already exist in the collection. It compares the _id property value of the specified items with the _id property values of the items in the specified collection.

  • If an item in the collection has the specified _id value, bulkSave() uses update() to update the item in the collection, triggering the beforeUpdate() and afterUpdate() hooks for that item if they have been defined.
  • If none of the items in the collection contain that _id value, the specified item does not have an _id property, or if the specified item's _id property is undefined, bulkSave() uses insert() to add the specified item into the collection. This triggers the beforeInsert() and afterInsert() hooks for that item if they have been defined.

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

When saving items to a collection that has a reference field, set the values of the reference fields to the referenced item's _id value or the entire referenced item object.

The maximum size of an item that you can save to a collection is 500kb.

Notes:

  • If an item's _id property value is set to null or an empty string, an error is thrown.
  • Bulk operations are limited to 1000 items per function call.
  • The bulkSave() function is not supported for Single Item Collections.
  • The bulkSave() function 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 bulkSave() will fail and issue an error.
Method Declaration
Copy
Method Parameters
collectionIdstringRequired

The ID of the collection to save the item to.

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


itemsArray<object>Required

The items to insert or update.

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


optionsWixDataOptions

An object containing options to use when processing this operation.

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