IndexedDB - Failed to execute 'add' on 'IDBObjectStore' - insert 100,000 records

Viewed 77

Is there a maximum of transactions a objectStore can perform in a single transaction?

let tx = this.#database.transaction(store, 'readwrite');

tx.onerror = (err) => console.warn(err);
tx.oncomplete = (ev) => console.log("Trans Complete-Time(ms):",Date.now()-start);

// create store
let txStore = tx.objectStore(store);

let iCnt = 0;
addNext();

function addNext(){
    if (iCnt < oJson.length) {
        if (iCnt % 1000 === 0) console.log({iCnt});
        txStore.add(oJson[iCnt++]).onsuccess = addNext();
    }
}

The oJson object has 30,000 objects:

{ id:'19276', name: 'John'}...
each record has a unique id. 

The error is:

Uncaught DOMException: Failed to execute 'add' on 'IDBObjectStore': Evaluating the object store's key path did not yield a value.

If the same data is added into the indexedDB in 2 steps, 15000 the first step and 15000 the second step, all objects are accepted.

If I "add" or "put" each line one by one all the 30,000 records will be entered but the process is extremely slow because it creates a transaction for each record.

I use chrome and I have tried it in different computers and I get a similar error but at a different record which makes me think it has something to do with memory and not so much limits of the objectStore or transaction object.

0 Answers
Related