title: How do I read an objects key in an indexeddb autoincrement objectstore, given an index
body: <p>This question in code form, I can use <code>.put(doc, key)</code> to overwrite the object, but I cant figure out how to read its key</p>
  
  <pre><code>// After writing doc1 to an autoincrement
  // objectStore, I want to overwrite it 
  // later, I only know its index 
  // (not its key)
  
  var docs = [
    {'a':'doc1', 'my_index': 'anindex'},
    {'a':'doc2', 'my_index': 'anindex'}
  ];
  
  indexedDB.deleteDatabase('foo').onsuccess = function () { 
  
    var idb;
    var req = indexedDB.open('foo');
  
    function writeDocs(docs) {
  
      if (!docs.length) { 
        console.log('done writing');
        return;
      }
  
      var txn = idb.transaction(['some_store_name'], 'readwrite');
      var doc = docs.shift();
      console.log('writing', doc);
  
      var get = txn.objectStore('some_store_name').index('my_index')
        .get(doc.my_index);
  
      get.onsuccess = function(e) { 
  
        var key = null;
  
        if (e.target.result) { 
          // If there is a result here, I want to overwrite it
          // to do that I need its key, cant find it here?    
          console.log(e.target.result);
        }
  
        var dataReq = txn.objectStore('some_store_name').put(doc);
  
        dataReq.onsuccess = function (e) {
          console.log('wroted', e.target.result);
          writeDocs(docs);
        }
  
        dataReq.onerror = function () { 
          console.log('it broke');
          writeDocs(txn, docs);
        }
      }
    };
  
    req.onupgradeneeded = function(e) {
      var db = e.target.result;
      db.createObjectStore('some_store_name', {autoIncrement : true})
        .createIndex('my_index', 'my_index', {unique: true});
    };
  
    req.onsuccess = function(e) { 
      idb = e.target.result;
      writeDocs(docs);
    };
  }
  </code></pre>