I have successfully added the following to the objectStore when I created it:
{ name: "John Doe", age: 21 }
I used the options:
{ keyPath: "id", autoIncrement: true }
I am able to find that record and it shows the id = 1
. However, when I run this command below, it throws an error:
var store = db.transaction( [ "employees" ], "readwrite" ).objectStore( "employees" );
var request = store.put( { name: "John Doe", age: 32 }, 1 );
This throws:
DataError: DOM IDBDatabase Exception 0
Does anyone know what's wrong? Am I specifying the key incorrectly?
Update
The IndexedDB spec states that the second parameter should be allowed:
interface IDBObjectStore {
...
IDBRequest put (any value, optional any key);
...
};
However, it doesn't work, but this does work:
store.put( { name: "John Doe", age: 32, id: 1 } );
That is a bug to require that. Unless I'm still doing something incorrectly.
The error means (see here for full list):
Data provided to an operation does not meet requirements.
The object store uses in-line keys and the key parameter was provided.
You are specifying a keypath
which instruct the store to use in-line keys, but as you specified an out-of-line key as second parameter to put
it will fail.