> Portal Navigation: > > - Append `.md` to any URL under `https://dev.wix.com/docs/` to get its markdown version. > - Pages are either content pages (article or reference text) or menu pages (a list of links to child pages). > - To get a menu page, truncate any URL to a parent path and append `.md` (e.g. `https://dev.wix.com/docs/sdk.md`, `https://dev.wix.com/docs/sdk/core-modules.md`). > - Top-level index of all portals: https://dev.wix.com/docs/llms.txt > - Full concatenated docs: https://dev.wix.com/docs/llms-full.txt # Method name: data.items.bulkSave(dataCollectionId: string, items: Array, options: WixDataBulkSaveOptions) # Method Link: https://dev.wix.com/docs/sdk/business-solutions/data/items/bulk-save.md # Method Description: Inserts or updates a number of items in a collection. The `bulkSave()` method 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()` method 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()`](https://dev.wix.com/docs/velo/api-reference/wix-data/hooks/before-insert.md) and [`afterInsert()`](https://dev.wix.com/docs/velo/api-reference/wix-data/hooks/after-insert.md) hooks for that item if they have been defined. 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. > **Notes:** > - The maximum size of an item that you can save 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 `bulkSave()` method is not supported for [single-item collections](https://support.wix.com/en/article/cms-adding-and-setting-up-a-single-item-collection). > - The `bulkSave()` method does not support multi-reference fields. For multi-reference fields, use `replaceReferences()` or `insertReference()`. > - [Translatable collections](https://support.wix.com/en/article/wix-multilingual-translating-cms-collection-content) 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()` fails and issues an error. # Method Permissions: - Write Data Items # Method Permissions Scopes IDs: - SCOPE.DC-DATA.WRITE # Method Code Examples: ## Save multiple items in a collection ```javascript import { items } from "@wix/data"; async function bulkSaveItems() { const toSave1 = { "title": "Mr.", "first_name": "John", "last_name": "Doe" }; const toSave2 = { "title": "Ms.", "first_name": "Jane", "last_name": "Doe" }; const results = await items.bulkSave("myCollection", [toSave1, toSave2]); const inserted = results.inserted; // 2 const insertedIds = results.insertedItemIds; // See below const updated = results.updated; // 0 const skipped = results.skipped; // 0 const errors = results.errors; // [] } /* insertedIds is: * * [ * "d9ea65a6-726a-4c3e-b97d-1128c0a06b5f", * "472c1da9-e5e4-4620-8ee3-962e9d1a7df5" * ] */ ``` ## Save multiple items with specified IDs in a collection ```javascript import { items } from "@wix/data"; async function bulkSaveItems() { const toSave1 = { "_id": "00001", "title": "Mr.", "first_name": "John", "last_name": "Schmoe" }; const toSave2 = { "_id": "00003", "title": "Prof.", "first_name": "Jan", "last_name": "Doey" }; const results = await items.bulkSave("myCollection", [toSave1, toSave2]); const inserted = results.inserted; // 1 const insertedIds = results.insertedItemIds; // ["00003"] const updated = results.updated; // 1 const skipped = results.skipped; // 0 const errors = results.errors; // [] } ``` ## Save multiple items including a reference to another item using the referenced item's ID ```javascript import { items } from "@wix/data"; async function bulkSaveItems() { const countryId = "id-of-usa-item"; const toSave1 = { "title": "Mr.", "first_name": "John", "last_name": "Doe", "country": countryId }; const toSave2 = { "title": "Ms.", "first_name": "Jane", "last_name": "Doe", "country": countryId }; const results = await items.bulkSave("myCollection", [toSave1, toSave2]); const inserted = results.inserted; // 2 const insertedIds = results.insertedItemIds; // see below const updated = results.updated; // 0 const skipped = results.skipped; // 0 const errors = results.errors; // [] } /* insertedIds is: * * [ * "d9ea65a6-726a-4c3e-b97d-1128c0a06b5f", * "472c1da9-e5e4-4620-8ee3-962e9d1a7df5" * ] */ ``` ## Save multiple items including a reference to another item using the reference item ```javascript import { items } from "@wix/data"; async function bulkSaveItems() { const countryItem = // Get country item const toSave1 = { "title": "Mr.", "first_name": "John", "last_name": "Doe", "country": countryItem }; const toSave2 = { "title": "Ms.", "first_name": "Jane", "last_name": "Doe", "country": countryItem }; const results = await items.bulkSave("myCollection", [toSave1, toSave2]); const inserted = results.inserted; // 2 const insertedIds = results.insertedItemIds; // see below const updated = results.updated; // 0 const skipped = results.skipped; // 0 const errors = results.errors; // [] } /* insertedIds is: * * [ * "d9ea65a6-726a-4c3e-b97d-1128c0a06b5f", * "472c1da9-e5e4-4620-8ee3-962e9d1a7df5" * ] */ ``` ## default ```javascript try { const result = await items.bulkSave("collection-0.15029624698241473", [ { _id: "6892593d-d57f-428d-bc53-3f0870a1beef", name: "Sample Item", phone: "+972501234567", date: Date.now(), image: "https://static.wixstatic.com/media/503ea4_ed9a38760ae04aab86b47e82525fdcac~mv2.jpg" } ], { appOptions: {}, showDrafts: false, suppressHooks: false }); return result; } catch (error) { console.error(error); throw error; } ```