Best practices for index optimization
Now that you have covered a lot of ground and explored various MongoDB indexes, let's look at the best practices and guidelines for optimizing indexes.
Creating indexes for your MongoDB database is an important task that can—and will—determine the speed and performance of the queries and the overall database performance. As you've seen throughout this chapter, creating indexes is easy and intuitive, and there are many types of indexes that cover almost every possible use case. However, having too many or inadequate indexes can hamper the database performance, and special care should be taken when deciding on what to index and how to index.
One of the most important features of an index is its selectivity—the measure of the number of documents associated with a single index value. An index is said to be selective if it has many unique values and few duplicates. Cardinality, on the other hand, refers to several...