---
title: "Bulk Insert: How to Work With Bulk Insert Operation"
description: "Use RavenDB's BulkInsertOperation to efficiently insert large volumes of documents, counters, time series, and attachments in a single batch."
url: "https://docs.ravendb.net/7.2/client-api/bulk-insert/how-to-work-with-bulk-insert-operation"
version: "7.2"
language: "nodejs"
---

# Bulk Insert: How to Work With Bulk Insert Operation

> Client language: Node.js. Also available for [C#](https://docs.ravendb.net/7.2/client-api/bulk-insert/how-to-work-with-bulk-insert-operation.md), [Java](https://docs.ravendb.net/7.2/client-api/bulk-insert/how-to-work-with-bulk-insert-operation.java.md).
>
> RavenDB publishes an official agent skill for coding assistants at https://docs.ravendb.net/skills/ravendb/SKILL.md (also installable with `npx skills add ravendb/skills`). The skill describes itself as: "Read this before writing any RavenDB query, client call or /databases/ request. Covers server setup, document modelling, the Node.js, .NET and Python clients, RQL, indexes, vector search and AI agents. Code written from recall tends to run and return the wrong rows, because RQL resembles SQL and the clients take field names as plain strings."

One of the features that is particularly useful when inserting large amount of data is `bulk inserting`.  
This is an optimized time-saving approach with few drawbacks that will be described later.

### Syntax

```javascript
documentStore.bulkInsert([database]);
```

| Parameters | | |
| - | - | - |
| **database** | `string` | The name of the database to perform the bulk operation on.<br />If `null`, the DocumentStore `Database` will be used. |

| Return Value | |
| - | - |
| `BulkInsertOperation` | Instance of `BulkInsertOperation` used for interaction. |

## `BulkInsertOperation`

#### Methods

| Signature | Description |
| - | - |
| **async abort()** | Aborts the bulk insert operation. Returns a `Promise`. |
| **async store(entity, \[metadata])** | store the entity, identifier will be generated automatically on client-side. Optional, metadata can be provided for the stored entity. Returns a `Promise`. |
| **async store(entity, id, \[metadata])** | store the entity, with `id` parameter to explicitly declare the entity identifier. Optional, metadata can be provided for the stored entity. Returns a `Promise`. |
| **async finish()** | Finish bulk insert and flush everything to the server. Returns a `Promise`. |

### Limitations

There are a couple limitations to the API:

- The bulk insert operation is broken into batches, each batch is treated in its own transaction
  so the whole operation isn't treated under a single transaction.

### Example

#### Create bulk insert

Here we create a bulk insert operation and insert a million documents of type Employee

```javascript
{
  const bulkInsert = documentStore.bulkInsert();
  for (let i = 0; i < 1000000; i++) {
      const employee = new Employee("FirstName #" + i, "LastName #" + i);
      await bulkInsert.store(employee);
  }

  await bulkInsert.finish();
}
```

## See also

- [What is a Document Store](https://docs.ravendb.net/7.2/client-api/what-is-a-document-store.nodejs.md)
- [What is a Session and How Does it Work](https://docs.ravendb.net/7.2/client-api/session/what-is-a-session-and-how-does-it-work.nodejs.md)
- [Bulk Insert: How to Add Attachments](https://docs.ravendb.net/7.2/document-extensions/attachments/store-attachments/bulk-insert.nodejs.md)
- [Bulk Insert: How to Append Time Series](https://docs.ravendb.net/7.2/document-extensions/timeseries/client-api/bulk-insert/append-in-bulk.nodejs.md)
- [Working with Document Identifiers](https://docs.ravendb.net/7.2/client-api/document-identifiers/working-with-document-identifiers.md)
- [Create or Modify Counters](https://docs.ravendb.net/7.2/document-extensions/counters/create-or-modify.nodejs.md)
- [What is the Changes API](https://docs.ravendb.net/7.2/client-api/changes/what-is-changes-api.nodejs.md)
