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!
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
Alex Parker980 Points
If a field is not indexed, can we sort?
If a field is not indexed, can we sort? _id is always indexed, but with the title field we did it manually. And if we didn't make it indexed, would we able to sort?
Inge L30,058 Points
Yes, index just impact the database performance. If you have to find document with title "You name it" without index, with any engine, that would need to scan every document in the collection and that will take very long if there is a huge number of documents. Practicaly you are avoiding to look at entire collection, because if you indexed you can think of it as a ordered list of things, and in MongoDB the way it is ordered is something about B-tree. If you have ordered it is then very fast to search it. Index will slow writes(insert) but you can find a document fast and that is how you want to have just indexes (small enough) to satisfy queries client needs. You can optimize to have index just where you need to query and if you just inserting a documents then you don't need index at all. You are always optimizing percentage on reads and writes for that collection.