# Use bulkInsert to load lots data at once

**URL:** <https://forum.wixstudio.com/t/use-bulkinsert-to-load-lots-data-at-once/29191>\
**Category:** Show and tell\
**Tags:** tips, code\
**Created:** [July 7, 2020, 6:17pm UTC](https://forum.wixstudio.com/t/use-bulkinsert-to-load-lots-data-at-once/29191 "2020-07-07T18:17:59Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![edb](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/edb/32/3202_2.png) [@edb](https://forum.wixstudio.com/u/edb)\
**Post date:** [July 7, 2020, 6:17pm UTC](https://forum.wixstudio.com/t/use-bulkinsert-to-load-lots-data-at-once/29191/1 "2020-07-07T18:17:59Z")

</div>

Got a lot of data that you want to add to a collection ? Try using the **bulkInsert** function. It’s much faster than individual inserts for large amounts of data.

As an example let’s load historical stock price data. You can get free historical quotes from a number of sites on the net. To get some data, we’ll use a backend **fetch** function. See the end of this post for the fetch implementation. The output of our fetch contains a prices array which looks like this:

```javascript
{
 "prices": [
             {
               "date": 1562074200,
               "open": 143.6999969482422,
               "high": 145.63999938964844,
               "low": 142.55999755859375,
               "close": 144.6199951171875,
               "volume": 279700,
               "adjclose": 144.6199951171875
             },...
          ]
 }

```

To use bulkInsert, your data will need to be in an array with attributes matching the name of the attributes in your collection.  
We have a collection called stock\_quotes with the same attributes as the prices array above, plus a few more. Attributes in the collection that are not in the array are left as null.

```javascript
export function loadData(inputData) {
 let options = {
                 "suppressAuth": true,
                 "suppressHooks": true
                };
 return wixData.bulkInsert("stock_quotes", inputData, options)
        .then((results) => {
                             let response = {
                             "inserted": results.inserted,
                             "skipped": results.skipped,
                             "errors": results.errors
                             };
                             return response;
          })
        .catch((err) => {
                            return err
        });
}

```

Note that bulkInsert has a limit of 1000 rows so if you want to load more, you need to iterate through your input data 1000 items at a time.  
Tip 1: Don’t iterate through your input data on the backend. If you have a lot of data, you can easily hit the timeout on calls to the backend.  
Tip 2: Use the options to turn off hooks and authorization to make it faster.  
Tip3: If update-or-insert is what you need, check out bulkSave( ) There are also bulkRemove and bulkUpdate functions.

* * *

From the example, the fetch looks like this:

```javascript
import { fetch } from 'wix-fetch';

export function myFetch() {
     return fetch("https://apidojo-yahoo-finance-v1.p.rapidapi.com/stock/v2/get-historical-data?frequency=1d&filter=history&period1=1383748200&period2=1562086800&symbol=wix", {
 "method": "get",
 "headers": {
 "Content-Type": "application/json",
 "x-rapidapi-host": "apidojo-yahoo-finance-v1.p.rapidapi.com",
 "x-rapidapi-key": "000-get-a-free-api-key-000"
            }
        })
        .then((httpResponse) => {
                if (httpResponse.ok) {
                          return httpResponse.json();
                    } else {
                          return Promise.reject("Fetch did not succeed");
                    }
        })
        .catch((err) => {
            console.log("error in fetch=", err);
            return err
        })
        .then((dataToInsert) => {
            return dataToInsert.prices;
        })
}

```

---

<div class="post-metadata">

**Author:** ![rbekind2020](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/rbekind2020/32/10170_2.png) [@rbekind2020](https://forum.wixstudio.com/u/rbekind2020)\
**Post date:** [August 12, 2020, 10:42am UTC](https://forum.wixstudio.com/t/use-bulkinsert-to-load-lots-data-at-once/29191/2 "2020-08-12T10:42:56Z")

</div>

Thank you for your great advice.
