IDBCursor.update

This article is in need of a technical review.

« IDBCursor

The IDBCursor.update method returns an IDBRequest object, and, in a separate thread, updates the value at the current position of the cursor in the object store. If the cursor points to a record that has just been deleted, a new record is created.

Syntax

IDBRequest update (any value);

Example

// Open our object store and then get a cursor list of all the different data items in the IDB to iterate through
    var objectStore = db.transaction('toDoList').objectStore('toDoList');
    objectStore.openCursor().onsuccess = function(event) {
      var cursor = event.target.result;
      
      // Find a cursor that you want to update  
      if(cursor.value.taskTitle == "Walk the dog") {
        cursor.value.hours = "19";
        cursor.value.minutes = "30";

        var request = cursor.update(cursor.value);

        request.onsuccess = function() {
          // take further action once the record is successfully updated
        }
      }
      
      cursor.continue();
    }

Parameters

value
The value to be stored at the current position.

Returns

IDBRequest

A request object on which subsequent events related to this operation are fired.

Exceptions

This method may raise a DOMException with a DOMError of the following types:

Exception Description
TransactionInactiveError This IDBCursor's transaction is inactive.
ReadOnlyError The transaction mode is read-only.
InvalidStateError The cursor was created using IDBIndex.openKeyCursor, is currently being iterated, or has iterated past its end.
DataError

The underlying object store uses in-line keys and the property in value at the object store's key path does not match the key in this cursor's position.

DataCloneError The data being stored could not be cloned by the internal structured cloning algorithm.

Specifications

Specification Status Comment
Indexed Database API Candidate Recommendation  

Browser compatibility

Feature Chrome Firefox (Gecko) Internet Explorer Opera Safari (WebKit)
Basic support 12webkit
23
4.0 (2.0) 10 17 Not supported
Feature Android Firefox Mobile (Gecko) Firefox OS IE Phone Opera Mobile Safari Mobile
Basic support 4.4 6.0 (6.0) 1.0.1 10 17 Not supported

Be careful in Chrome as it still implements the old specification along the new one. Similarly it still has the prefixed webkitIndexedDB property even if the unprefixed indexedDB is present.

See also

  • Using IndexedDB
  • The reference application for the examples in this reference: To-do Notifications (view example live.) Not every snippet appears in this example, but every example uses the same data structure and syntax, and will make sense in the context of this application.

Document Tags and Contributors

Contributors to this page: chrisdavidmills
Last updated by: chrisdavidmills,