Video Transcript (English)
Hello! In this video, you’ll learn about indexes. We will discuss what indexes are, how they can improve performance, and the costs of using them. We’ll also review the most common index types.
Indexes are special data structures that store a small portion of the collection's data in an ordered form that is easy to traverse and search efficiently. Indexes point to the document identity and allow you to lookup, access, and update data faster.
Indexes are used in MongoDB to improve query performance. They can speed up queries, reduce disk I/O, and reduce the resources required for them.
Indexes also support queries, such as equality matches and range-based operations, and return sorted results.
Indexes store data in an ordered form based on the index fields and value sort order that are provided when the index is created.
Without indexes, MongoDB has to read every document in a collection by performing a collection scan, to check if it matches the query being run. It also needs to sort the results in memory if the query requires a sorted output.
When using an index, MongoDB only fetches the documents identified by the index based on the query and returns the results faster.
If the index includes all the information the query wants to retrieve, MongoDB does not need to read the document.
By default, there is only one index created per collection. This default index only includes the _id field.
Every query should use an index. This way, you can create additional indexes in your collections to cover your data queries.