> 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.bulkInsert(dataCollectionId: string, items: Array<any>, options: WixDataBulkInsertOptions)

# Method Link:

https://dev.wix.com/docs/sdk/data-items-sdk/data/items/bulk-insert.md

# Method Description:

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()`](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) 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.
When inserting items into a collection that has a multi-reference field, set the
values of the multi-reference fields to arrays of the referenced items' `_id` values or arrays of the
entire referenced item objects.
To save multi-reference values, specify `saveReferences: true` in the `options` 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](https://support.wix.com/en/article/cms-adding-and-setting-up-a-single-item-collection).
> - [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 `bulkInsert()` fails and issues an error.

# Method Permissions:

- Write Data Items

# Method Permissions Scopes IDs:

- SCOPE.DC-DATA.WRITE



# Method Code Examples:

## Insert multiple items into a collection

```javascript
import { items } from "@wix/data";

async function bulkInsertItems() {
  const toInsert1 = {
    "title":        "Mr.",
    "first_name":   "John",
    "last_name":    "Doe"
  };
  
  const toInsert2 = {
    "title":        "Ms.",
    "first_name":   "Jane",
    "last_name":    "Doe"
  };
  
  const results = await items.bulkInsert("myCollection", [toInsert1, toInsert2]);
  
  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"
 *  ]
 */
```



## Insert multiple items with specified IDs into a collection

```javascript
import { items } from "@wix/data";

async function bulkInsertItems() {
  const toInsert1 = {
    "_id":          "00001",
    "title":        "Mr.",
    "first_name":   "John",
    "last_name":    "Doe"
  };
  
  const toInsert2 = {
    "_id":          "00002",
    "title":        "Ms.",
    "first_name":   "Jane",
    "last_name":    "Doe"
  };
  
  const results = await items.bulkInsert("myCollection", [toInsert1, toInsert2]);
  
  const inserted = results.inserted; // 2
  const insertedIds = results.insertedItemIds; // ["00001", "00002"]
  const updated = results.updated; // 0
  const skipped = results.skipped; // 0
  const errors = results.errors; // []
}
```

## Insert multiple items including a reference to another item using the referenced item's ID

```javascript
import { items } from "@wix/data";

async function bulkInsertItems() {
  const countryId = "id-of-usa-item";
  
  const toInsert1 = {
    "title":        "Mr.",
    "first_name":   "John",
    "last_name":    "Doe",
    "country":      countryId
  };
  
  const toInsert2 = {
    "title":        "Ms.",
    "first_name":   "Jane",
    "last_name":    "Doe",
    "country":      countryId
  };
  
  const results = await items.bulkInsert("myCollection", [toInsert1, toInsert2]);

  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"
 *  ]
 */
```

## Insert multiple items including a reference to another item using the reference item

```javascript
import { items } from "@wix/data";

async function bulkInsertItems() {
  const countryItem = // Get country item
  
  const toInsert1 = {
    "title":        "Mr.",
    "first_name":   "John",
    "last_name":    "Doe",
    "country":      countryItem
  };
  
  const toInsert2 = {
    "title":        "Ms.",
    "first_name":   "Jane",
    "last_name":    "Doe",
    "country":      countryItem
  };
  
  const results = await items.bulkInsert("myCollection", [toInsert1, toInsert2]);
    
  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.bulkInsert("collection-0.241418997425757", [
        {
          _id: "6892593d-d57f-428d-bc53-3f0870a1beef",
          _createdDate: Date.now(),
          _updatedDate: Date.now(),
          phoneNumber: "+972501234567",
          image: "https://static.wixstatic.com/media/503ea4_ed9a38760ae04aab86b47e82525fdcac~mv2.jpg"
        }
      ], {
        appOptions: {},
        showDrafts: false,
        suppressHooks: false
      });
      return result;
    } catch (error) {
      console.error(error);
      throw error;
   }
```