I have 6 indexed fields in my collection. My app uses aggregation queries with different combinations of them. Here is some possible examples:
1. {$match: {$and: [{field1: {$in: [1,2,3]}}, {$field5: {$gt: 8}}]}}
2. {$match: {$and: [{field2: {$nin: [4,5,6]}}, {$field5: {$lte: 8}}, {$field6: 5}]}}
3. {$match: {field1: {$in: [7,8,9]}}}
As I said before, all fields are indexed. Of cource, when I'm executing first query, explain() function tells me, that only one index is being used. The number of fields in query depends on user's choices.
Should I create indexes for every combination of fields (I mean like {field1:1,field2:1}, {field1:1,field2:1,field3:1} etc) or I can just make one compound index for all the fields like {field1:1,field2:1,field3:1,field4:1,field5:1,field6:1}?
I think the first decision could be a little weird, because there is so much combinations for 6 fields.