bulkInsert( )


Developer Preview

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

Adds a number of items to a collection.

The bulkInsert() method returns a Promise that resolves after the items have been added to the specified collection. The Promise is rejected if the current user does not have "create" permissions for the collection. Items are skipped if they include an _id property whose value matches an existing ID in the collection. This means that bulkInsert() cannot overwrite an existing item in the collection.

Calling the bulkInsert() method triggers the beforeInsert() and afterInsert() events for each item that is inserted, if these events have been defined.

When inserting items into 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 bulkInsert() method adds the following properties and values to the item when it adds it to the collection:

  • _id: A unique identifier for an item in a collection, if the item doesn't have one or has one that is undefined. You can optionally provide your own ID. Once an ID is assigned to an item it cannot be changed.
  • _createdDate: The date the item was added to the collection.
  • _updatedDate: The date the item was modified. When the item is first added, the createdDate and updatedDate are the same.

Any valid JavaScript object can be added as a property value. The bulkInsert() 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.

Notes:

  • The maximum size of an item that you can add to a collection is 500kb.
  • 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 method call.
  • The bulkInsert() method is not supported for single-item collections.
  • The bulkInsert() method does not support multi-reference fields. For multi-reference fields, use 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 bulkInsert() fails and issues an error.
Permissions
Write Data Items
Learn more about app permissions.
Method Declaration
Copy
Method Parameters
dataCollectionIdstringRequired

ID of the collection to which the items belong.


itemsArray<Partial>Required

Data items to insert.


optionsWixDataOptions

Options to use when processing this operation.

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