Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Databases Mongo Basics Working With Collections Managing Collections

Frederic Ronaldi
Frederic Ronaldi
13,732 Points

What is index exactly?

Hi, i still don't get it, so what is index exactly? Does it only improve the speed of reading the database? If so, how do the indexes work and do they work like sorting things? Then how do the data are organized in the database? Thanks

1 Answer

When you look something up in a book, you would look at the index at the back. It records all the words and a direct link to the page the word is on. An index in a database does the same, it stores all the data in the field and a direct link to the record. As this index is quick to search (it is in order) it makes finding records quicker. It means the database doesn't have to search through every record to find something. However, there is a cost to do the index. It takes memory and time to create and maintain. This means you don't want to index every field, just those you are most likely to need to refer to quickly. This is usually any I'd fields.

Thanks for the brief explanation mate.