Skip to content
Advertisement

Uncaught TypeError: store.put is not a function at store.onsuccess

I can’t update any data in IndexedDb. When I run the code it says “store.put is not a function at store.onsuccess”.

  • I tried from many browsers, same error in all
  • I also tried .update instead of .put function but it didn’t work and gave the same error
const request = window.indexedDB.open("AdminDatabase");

    request.onsuccess = (event) => {
      const db = event.target.result;

      const txn = db.transaction('floors', 'readwrite');

      const store = txn.objectStore('floors').get(parseInt(getRoomButtonNumber));
    
      store.onsuccess = function (event) {
        var floorDataFromDb = event.target.result;
        console.log("RenameFloor: getDbResult: FloorName: " + floorIdFromDb.Name);

        floorDataFromDb.Name = person;

        console.log("RenameFloor: Json New Name: " + floorDataFromDb.Name);

        //In this line caught error

        store.put(floorDataFromDb);

        store.onsuccess = function (event) {
          console.log("floorData Updated: " + event.target.result);

        }


      };

      store.onerror = function (event) {
        console.log("GET Error DB: " + event);

      };
    };

IndexedDb Browser View

Advertisement

Answer

You issue is on this line: const store = txn.objectStore('floors').get(parseInt(getRoomButtonNumber));

You define store as an IDBRequest.

Obviously, this does not have a put method. You would instead change it to this:

const store = txn.objectStore('floors');

const res = store.get(parseInt(getRoomButtonNumber));

res.onsuccess = evt => {
  ...
  store.put(data, key);
  ...
}

res.onerror = evt => {
  ...
}
User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement