In this presentation, we have listed the importance of MongoDB indexing and various indexing strategy one needs to consider for successful project execution.
2. Imagine you want to learn more about database performance, and you have in your
hands a very large book about databases. How can you search for your topic of
interest with fewer efforts?
Without a proper index of a book (usually located on the front page), it would be a
time-consuming and tedious job to find out the exact page where the database
performance topic is being written. Similarly, when you ask for some document in a
database, the database tries to use an index to quickly find the results for you. If
there’s no index to use as a reference, it has to check each document, the same way
you would have to if your book didn’t have an index.
Introduction
3. What is Indexing?
Indexing is a data structure technique that is used to quickly locate and access
the data in a database. For any kind of database, indexing is of prime importance,
as it helps in the quick and efficient execution of queries. Indexes in MongoDB are
like indexes in any other database. MongoDB uses indexes in order to make
query processing more efficient. Failure to use indexes in MongoDB will force the
database to perform a full collection scan, that is, scan through all the documents
in the collection in order to select documents that match an issued query
statement
4. Types of Indexing
1. Single Field Index : It is used to create an index on a single field of a document
2. Multikey Index: To index a field that holds an array value, MongoDB creates an index key for
each element in the array.
3. Compound Index: It is used to create an index on multiple fields in a document.
4. Text Index: It supports searching for string content in a collection.
5. Hash Indexes: It calculates the value of a particular field and is used to support
equality matches, not range-based searches.
6. Geospatial index types: They are useful for those who work with geospatial
coordinate data.
7. Partial Index: They only index the documents in a collection that meet a specified filter
expression.
5. Indexing Strategy
1. Create Indexes to support your queries
2. Ensure Indexes fit in RAM
3. Use ESR Rule (Equality , Sort, Range)
4. Eliminate the Unused Index
5. Avoid Regular Expressions
(a) Avoid regular expressions that are not left anchored or rooted
(b) Avoid regular expressions that are case insensitive
6. Use Covered queries
7. Indexes and Collation
6. Conclusion
The main takeaway is obvious: create indexes to support your queries — the
benefits are endless. Otherwise, queries require full collection scans, which are
limited by your server’s disk subsystem I/O.
For more details, please read full article from BigStep Technologies website.