0
votes

Regarding to What is the best way to create various IndexedDB objectStores within the same script? I created two objectstores :

var opinionObjectStore = thisDb.createObjectStore("opinion", {keyPath: "id", autoIncrement: false});
var commentObjectStore = thisDb.createObjectStore("comment", {keyPath: "id", autoIncrement: false});

Then I open a transaction and get the both objectstore:

var transo = myDataBase.transaction(["opinion", "comment"], "readwrite");
var opinionsObjectStore = transo.objectStore("opinion");
var commentsObjectStore = transo.objectStore("comment");

Then I create my "need to be stored" objects:

var comment = {id: "myid"};
var resp = commentsObjectStore.add(comment);
// other instructions [...]
var opinion = {};
opinion.id = tagElement.id;
var resp = opinionsObjectStore.add(opinion);

And I get an exception:

DataError: Data provided to an operation does not meet requirements.
[Break On This Error]
var resp = commentsObjectStore.add(comment);

Could you help me to let me add my comment and don't throw an exception?

I already read DOM IDBDatabase Exception 5 when adding data in indexedDB and Error "Data provided to an operation does not meet requirements" when trying to add data to indexedDB which do not help.

3

3 Answers

0
votes

DataError is key error. So it must be you are not providing a key or the key is not valid.

However from you code, you are providing a valid key, it may be the key already exists. In that case browser should throw ConstraintError. Which browser is it?

Also clear app data (IndexedDB data) in your browser and try again.

0
votes

Maybe try my indexedDBViewer, with that you can check your indexeddb structure + data. Maybe with this you can figure out what is wrong. I think it is something with the object store definition of comments. Maybe you initially created the object store with other options, and didn't get recreated with the version you provide now.

You can find my indexeddbviewer here and here you find a blogpost on how to use it. If you are a Visual Studio developer you can also search for the "indexedDBViewer" package on nugget.

0
votes

The problem is found:

tagElement.id;

If tagElement is a xml node from :

liveXml.find('Comment').each(function(){
    var tagElement = $(this);

Then tagElement.id is undefined, but tagElement.attr('id') is defined. jQuery matters!