From the course: MongoDB Essential Training

Unlock the full course today

Join today to access over 23,200 courses taught by industry experts.

Indexes

Indexes

- [Narrator] Imagine you have to search for the phone numbers of all of your friends. And to do that, you are given a phone book which contains everyone in your area. But for whatever reason, it's not alphabetically sorted. Not great. You'd have to go through the entire book item by item. It would be much easier to retrieve the data you need if the phone book was sorted alphabetically, that is if there was an index on the last name associated for each record, like here. Now getting the phone numbers is a lot easier. Indexes work in a similar way in databases. When you perform a query on your database, the operation needs to find the data you are looking for. If you haven't defined an index, the database needs to check every document in the collection you are querying to see if it matches the query statement, which is also called the query predicate. This is called a collection scan and is very inefficient. An index…

Contents