Compound Indexes
MongoDB supports compound indexes, where a single index structure holds references to multiple fields [1] within a collection’s documents.
[1] MongoDB imposes a limit of 31 fields for any compound index.
Creating compound indexes can help. It helps in two ways.
By having more than one key
- the combine selectivity increases.
- the index can help serve more than one query or a query and sort operations.
All in all, having fewer indexes covering your queries can be a performance gain because less space is required and it takes less time to process and update indexes as documents are being written. But, this is a balancing act and really what you need to do is look at your system, your use case scenario, measure performance, and see what works best.