15027

DOM IDBDatabase Exception 5 when adding data in indexedDB

My object structure is like this:

var test={ "id":"A", "ChanName":"Discovery", "LCN":10 };

This is the snippet that creates the object store:

var objectStore = db.createObjectStore('Dat', { keyPath:'test.id',autoIncrement: false}); var trans = db.transaction(["Dat"], webkitIDBTransaction.READ_WRITE); var store = trans.objectStore("Dat"); var request=store.put(test);

When i try to add the test object i get this exception DATA_ERR: DOM IDBDatabase Exception 5. Please can you advice on what is wrong here? I am using chrome 18 to test this.The creation of object store is fine,but not able to add data

Answer1:

An IndexedDB Exception 5 is thrown when the "Data provided to an operation does not meet requirements." This is typically because you've added an index, for example, while providing an object missing that attribute.

Here, it appears your test object doesn't match what you've specified as a keypath.

If you want id as a key your createObjectStore would have to be like this:

var objectStore = db.createObjectStore('Dat', { keyPath:'id',autoIncrement: false});

As a further example, alternatively, with your keyPath as is your test object would need to look like this to not throw this error:

var test={ test: { "id":"A" }, ChanName:"Discovery", LCN:10 };

Recommend

  • How to avoid 'Win64' attribute is invalid when using variables in a WiX installer script?
  • Implementing a CAKeyFrameAnimation callback in MonoTouch at the end of an animation set?
  • Extracting XML data into MySQL
  • How to call NSURLSession Delegate in NSObject class not in viewcontroller?
  • Is it possible to have multiple cache entries depending on the language in drupal 8?
  • Error on SELECT*FROM statement android SQLite Database
  • How to store tree structure in sql?
  • How to observe the value of an NSTextField
  • How to use _COUNT in BaseColumns
  • SQLite: *prevent* PRIMARY KEY value from resetting after delete all rows [duplicate]
  • Performance degradation for Django with Gunicorn deployed into Heroku
  • Django all-auth Form errors not displaying
  • What is the difference between running in VS 2010 and running a builded EXE?
  • Exit from a loop that contains time delay immediately after a key is pressed
  • Converting a data frame into named object in R
  • xul/xpcom copy image from string to clipboard
  • Referring to individual variables in … with dplyr quos
  • Convert data type in R or Python
  • Grails Cannot get property 'id' on null object
  • How can I sum two different columns at once where one contains Decimal objects in pandas?
  • Issue with SVN Commit for certain File Extension
  • TFS 2015 - Waiting for an agent to be requested
  • URLConnection doesn't work since API 10 and higher?
  • 550 Access denied - Invalid HELO name
  • Problems installing Yesod for Haskell
  • Should I or shouldn't I use the CachingConnectionFactory with hornetq 2.4.1
  • How do I exclude a dependency in provided scope when running in Maven test scope?
  • Converting a WriteableBitmap image ToArray in UWP
  • Lost migrations and Azure database is now out of sync
  • Why value captured by reference in lambda is broken? [duplicate]
  • Launch Runnable Jar from Web Start
  • How to convert from System.Drawing.Color to Excel.ColorFormat in C#? Change comment color
  • javascript inside java/jsp code
  • Android Studio and gradle
  • IndexOutOfRangeException on multidimensional array despite using GetLength check
  • Bitwise OR returns boolean when one of operands is nil
  • sending mail using smtp is too slow
  • costura.fody for a dll that references another dll
  • Binding checkboxes to object values in AngularJs
  • How can i traverse a binary tree from right to left in java?