Reputation: 1140
I have a secondary non-unique key named 'tileId' which I would like to use for searching. Therefore, I have created the following index:
this.pouchDB.createIndex({
index: {
fields: ['tileId']
}
});
Then it works fine when I'm using the following selector:
selector: {tileId: 1234567}
But when I try to search for a list of values with the following selector, it works but gives a warning about no matching index found:
selector: {tileId: {$in, [1234567, 2345678]}}
Finally, I want to add several more similar fields to this query to get something like this:
selector: {tileId: {$in, [1234567, 2345678]},
category: {$in, [list of categories]},
subcategory: {$in, [list of subcategories]}
}
Is it doable, and how?
Upvotes: 0
Views: 414
Reputation: 1765
As I understand it, the current implementation of PouchDB Find only utilizes an index for contiguous keys (tileId
values in this case). If you specify a query which interrogates a disparate set of records by tileId
e.g. using an $or
or $in
clause, the (very basic) query planner elects not to use tileId
as the basis for an index scan at all.
I think you'd be better off issuing multiple queries rather than using $in
for the tileId
. The additional filters maybe relatively cheap if the number of documents with the specified tileId
is modest.
Upvotes: 1