I have a huge collection of millions of records, there will be 4 fields used to fetch data, lets say f1, f2, f3
for filtering and f4
for data sorting. There will be 3 types of queries:
1) filter by f1 AND f2, and sort by f4
2) filter by f1 AND f2 AND f3, and sort by f4
3) filter by f1 AND f2 AND few additional fields, and sort by f4
So sorting is always by f4. First 2 types of queries will be mostly used. Additional fields in the case 3 might be any field in the collection (search functionality), so I'm not going to use them for indexing.
My suggestion is that the only composed key (f1, f2, f3, f4)
might be the best solution, but as I have almost no experience in mongoDb I decided to ask you guys.