You are currently browsing legacy 4.0 version of documentation. Click here to switch to the newest 5.1 version.

We can help you with migration to the latest RavenDB

Contact Us Now
see on GitHub

Bulk Insert: How to Work With Bulk Insert Operation

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.


database string Name of database for which bulk operation should be performed. If null then the database from DocumentStore will be used.
Return Value
BulkInsertOperation Instance of BulkInsertOperation used for interaction.



Signature Description
async abort() Aborts the bulk insert operation. Returns a Promise.
async store(entity, [metadata], [callback]) 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], [callback]) 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.


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.


Create bulk insert

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

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

    await bulkInsert.finish();