'mongo indexes where multiple filters & sorts are applied
Suppose I have the following schema:-
collection name- Test
{
"uid": "5e0e6a804888946fa61a1976",
"name": "abc",
"bookName":"xyz",
"rating": 5,
"category":"aa",
"isbn":"45656"
}
my main query is to find the test collection by "uid".
The use case is that, a user can filter based on no. of fields and any combination.
for eg 1:. he selects name :'abc', and selects 'rating' as '5',
next eg 2:; he can select cat: "some cat", and name :"some name".
What is the efficient way to have indexes/compound indexes on the patterns? which will work on any combination and any no. of selected fields by user. How can i make it to cover the query using indexes?
currently for eg1: i can create index- {name:1, rating:1}
for eg2: i can create index- {cat:1, name:1}
But in a case where no order is defined on how a user can select the filters? How can I solve it? Do I need to create all of the indexes with each combination possible?
Please help, and suggest any ideas.
My query is dynamic on find based on users selection on filters but uid is constant.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source | 
|---|
