'Best approach to MongoDB sorts, indexes vs application level?

Having in my collection several counters, I'm already doing queries with a compound index and several fields, together with the main counter.

However, what if I want to sort by any other of the counters I've got in my collection? Should I create an index per count field to use in the sort stage? Better a compound index with all counts mixed up and include everything?

If this is not feasible, I guess the only option left is to gather the whole set of results into memory at application level and sort it in there?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source