Javascript: Searching indexeddb using multiple indexes
For your example, compound index still work, but requires two compound indexes
objectStore.createIndex('ssn, email, age', ['ssn', 'email', 'age']); // corrected objectStore.createIndex('ssn, email, name', ['ssn', 'email', 'name'])
And query like this
keyRange = IDBKeyRange.bound( ['444-44-4444', 'bill@bill@company.com'], ['444-44-4444', 'bill@bill@company.com', '']) objectStore.index('ssn, email, age').get(keyRange) objectStore.index('ssn, email, age').get(['444-44-4444', 'bill@bill@company.com', 30]) objectStore.index('ssn, email, name').get(['444-44-4444', 'bill@bill@company.com', 'Bill'])
Indexes can be arranged in any order, but it is most efficient if most specific come first.
Alternatively, you can also use key joining. Key joining requires four (single) indexes. Four indexes take less storage space and more general. For example, the following query require another compound index
SELECT * FROM customers WHERE ssn = '444-44-4444' and name = 'Bill' and age = 30
Key joining still work for that query.