> 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.save(dataCollectionId: string, item: Partial, options: WixDataSaveOptions) # Method Link: https://dev.wix.com/docs/sdk/business-solutions/data/items/save.md # Method Description: Inserts or updates an item in a collection. The `save()` method returns a Promise that resolves to the inserted or updated item after it has 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 `save()` method inserts or updates the specified item, depending on whether it already exists in the collection. It compares the `_id` property value 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, `save()` uses `update()` to update the item in the collection, triggering the `beforeUpdate()` and `afterUpdate()` hooks 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`, `save()` uses `insert()` to add the specified item to 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 if they have been defined. When saving an item to 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. > **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. > - The `save()` method does not support multi-reference fields. For multi-reference fields, use `insertReference() `or `replaceReferences()`. > - [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 `save()` fails and issues an error. # Method Permissions: - Write Data Items # Method Permissions Scopes IDs: - SCOPE.DC-DATA.WRITE # Method Code Examples: ## Save an item in a collection ```javascript import { items } from "@wix/data"; async function saveItem() { const toSave = { "title": "Mr.", "first_name": "John", "last_name": "Doe" }; const savedItem = await items.save("myCollection", toSave); console.log(savedItem); // See below } /* item is: * * { * "_id": "rifk4nrk-dj4o-djhe-oidk-fnoqw4oiglk4i", * "_owner": "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb", * "_createdDate": "2017-05-24T12:33:18.938Z", * "_updatedDate": "2017-05-24T12:33:18.938Z", * "title": "Mr.", * "first_name": "John", * "last_name": "Doe" * } */ ``` ## Save an item with a specified ID in a collection ```javascript import { items } from "@wix/data"; async function saveItem() { const toSave = { "_id": "00001", "title": "Mr.", "first_name": "John", "last_name": "Doe" }; const savedItem = await items.save("myCollection", toSave); console.log(savedItem); // See item } /* item is: * * { * "_id": "00001", * "_owner": "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb", * "_createdDate": "2017-05-24T12:33:18.938Z", * "_updatedDate": "2017-05-24T12:33:18.938Z", * "title": "Mr.", * "first_name": "John", * "last_name": "Doe" * } */ ``` ## Save an item including a reference to another item using the referenced item's ID ```javascript import { items } from "@wix/data"; async function saveItem() { const countryId = "id-of-usa-item"; const toSave = { "title": "Mr.", "first_name": "John", "last_name": "Doe", "country": countryId }; const savedItem = await items.save("myCollection", toSave); console.log(savedItem); // See below } /* item is: * * { * "_id": "rifk4nrk-dj4o-djhe-oidk-fnoqw4oiglk4i", * "_owner": "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb", * "_createdDate": "2017-05-24T12:33:18.938Z", * "_updatedDate": "2017-05-24T12:33:18.938Z", * "title": "Mr.", * "first_name": "John", * "last_name": "Doe", * "country": "id-of-usa-item" * } */ ``` ## Save an item including a reference to another item using the reference item ```javascript import { items } from "@wix/data"; async function saveItem() { const countryItem = // Get country item const toSave = { "title": "Mr.", "first_name": "John", "last_name": "Doe", "country": countryItem }; const savedItem = await items.save("myCollection", toSave); console.log(savedItem); // See below } /* item is: * * { * "_id": "rifk4nrk-dj4o-djhe-oidk-fnoqw4oiglk4i", * "_owner": "ffdkj9c2-df8g-f9ke-lk98-4kjhfr89keedb", * "_createdDate": "2017-05-24T12:33:18.938Z", * "_updatedDate": "2017-05-24T12:33:18.938Z", * "title": "Mr.", * "first_name": "John", * "last_name": "Doe", * "country": "id-of-usa-item" * } */ ``` ## default ```javascript try { const result = await items.save("collection-0.5404437414642547", { _id: "6892593d-d57f-428d-bc53-3f0870a1beef", name: "Updated Item", phoneNumber: "+972501234567", date: Date.now(), image: "https://static.wixstatic.com/media/503ea4_ed9a38760ae04aab86b47e82525fdcac~mv2.jpg" }, { suppressHooks: false }); return result; } catch (error) { console.error(error); throw error; } ```