I have two databases, one stored in indexedDB and the other in PouchDB (even though I am aware that PouchDB is built on top of indexedDB).
The dataset in indexedDB contains a list of rooms, which was saved through a previous page and is now being displayed on the current page.
On the other hand, the database in PouchDB consists of logs detailing the usage of each room recorded by an auditor. My goal is to iterate through the room list in indexedDB and check if each item appears in the audited rooms list. If a match is found, I want to set a flag to indicate this.
Below is my JavaScript code. Although the console log displays "true" at certain points during execution—indicating successful matches—the flag does not get properly set for the corresponding list item.
I am speculating whether the function continues to cycle through the audit records, possibly overwriting the value of "true"?
This snippet requests data from indexedDB and then calls a function to retrieve information from PouchDB:
function getRoomsInRoute() {
var routeNumber = $.jStorage.get('currentRoute', '');
var indexedDB = window.indexedDB || window.mozIndexedDB || window.webkitIndexedDB || window.msIndexedDB || window.shimIndexedDB;
openRequest = window.indexedDB.open("rooms", 1);
openRequest.onupgradeneeded = function() {
var db = openRequest.result;
var itemStore = db.createObjectStore("rooms", {keyPath: "room_id"});
var index = itemStore.createIndex("rooms", ["route_number"]);
};
openRequest.onerror = function(event) {
console.error(event);
};
// The rest of the JavaScript function...
and here is the accompanying function that interfaces with PouchDB to verify if auditing has been conducted:
function checkIfAudited(roomseq) {
// Implementation of logic to determine if a room has been audited in PouchDB.
}
I have extensively reviewed multiple questions and responses relating to comparing two arrays.
However, I am uncertain about how to incorporate a for
loop within pdb.allDocs
.
The output recorded via console.log
is as follows:
49 No matches
RoomSeq: 1; auditHour: 14; currentHour: 14; auditDay: 16 currentDay: 16; auditMonth: 0; currentMonth: 0; isAudited: true
2300 No matches
How can I modify the second function to halt and return "true" upon locating a matching record in PouchDB?