Is it possible to search an indexedDb object store with a "bound" keyRange on multiple keys. With the following data:
let simpleA = {
id: 'A',
bottomX: 2.5,
bottomY: 5.5,
topX: 3.5,
topY: 6.5
};
let simpleB = {
id: 'B',
bottomX: 4.2,
bottomY: 4.2,
topX: 4.8,
topY: 4.8
};
let simpleC = {
id: 'C',
bottomX: 8.5,
bottomY: 6.5,
topX: 9.5,
topY: 7.5
};
I have tried to create a index on multiple keys:
simpleStore.createIndex('bottomX bottomY topX topY', ['bottomX', 'bottomY', 'topX', 'topY']);
and a key range like this:
let keyRange = IDBKeyRange.bound(
[0,5,0,0],
[10,6,10,10]
);
And then creating a cursor:
let mycursor = index.openCursor(keyRange);
I was hoping that this would give me a result of simpleA
and simpleB
but not simpleC
, because the bottomY property is not in the range. However, as I tested this code, I realized that only the first key of the index is tests with the bound
keyrange.
Is there another way to achieve this range search on multiple keys?
For infos, I got the inspiration of the multiple index from this post: Javascript: Searching indexeddb using multiple indexes