I have some js that does a put to IndexedDB (in Chrome) using a readwrite transaction, then immediately queries from the same indexedDB objectstore using an index and a readonly transaction. Sometimes, the results I get back do not include the changes from my put and other times they. Is this sort of dirty ready to be expected in IndexedDB? Is there a way to avoid it?
Perhaps it's because I'm using 2 different txns and should be using just one (the reason for that is these calls are actually part of an api that separates puts and queries into different api calls that each have their own txns)? Still, seems like the first txn should be done and committed before my second one starts.
My pseudocode looks like this:
var txn = idb.transaction([DOC_STORE], "readwrite");
var putRequest = txn.objectStore(DOC_STORE).put(myDoc);
putRequest.onsuccess = function (e) {
var txn2 = idb.transaction([DOC_STORE], "readonly");
var store = txn2.objectStore(DOC_STORE);
var anotherRequest=store.index.openCursor();
.... walk the cursor here. Sometimes I don't see my changes from my put
};