createObjectStore method

Creates an object store.


var retVal = IDBDatabase.createObjectStore(name, optionalParameters);


name [in]

Type: DOMString

The name of the object store to be created.

optionalParameters [in, optional]

Type: any

An object literal containing one or more of the following attributes.


A DOMString value specifying the keypath for the object store


A Boolean value indicating whether the key value automatically increases as records are added to the object store.



This method can throw the following DOMException exceptions:

Note  As of a Windows Store app using JavaScript, the code property is deprecated in favor of the name property, which is preferred for standards compliance and future compatibility.
Exception propertiesCondition
name: InvalidStateError
code: DOMException.INVALID_STATE_ERR (11)

The method was not called within the context of a VERSION_CHANGE transaction or the request was made for an object that has been moved or deleted.

name: ConstraintError

An object store in the database already uses the name (case-sensitive).

name: InvalidAccessError

The autoIncrement attribute of the optionalParameters object is true; however, the keyPath attribute either an empty string ("") or an empty array.


Standards information


The following example shows createObjectStore being called in the context of an upgradeneeded event. For more info, see Creating and opening IndexedDB objects.

  if ( hIxHandle == null ) {
     handleError( "Can't open database (invalid handle)." );
  } else
       try {
          var sDBName = "ADatabase";
          var nDBVersion = 1.0;
          var req = sDBName, nDBVersion );
          req.onsuccess = function(evt) { 
             hDBHandle =;
          req.onerror = handleRequestEvent;
          req.onblocked = handleRequestEvent;
          req.onupgradeneeded = function(evt) {
             var hDBHandle =;
             var sStoreName = "MyObjectStore";
             var oDBOptions = { keyPath : "RecordID", autoIncrement : true };
             var oStore = hDBHandle.createObjectStore( sStoreName, oDBOptions );

             var oIxOptions = { unique: false, multientry: false };
             oStore.createIndex( "SortByTitle", "DeckTitle", oIxOptions );
             oStore.createIndex( "SortByDesc", "Description", oIxOptions );
       } catch( ex ) {
         handleError( ex.message );

See also




© 2016 Microsoft