MongoDB TutorialLesson 22Free preview
MongoDB Indexing/Search
This lesson is part of MongoDB · All levels
Summary
This lesson describes indexing as a way to speed up searches in MongoDB. Without an index, each query uses a collection scan that checks all documents; the index stores the data structure so that the search goes straight to its location. The index is created with createIndex() and its effectiveness can be monitored via the explain() command.
Key points
- Index makes searches much faster than collection scans.
- Db.koleksi.createIndex({ field: 1 }) makes the index go up, -1 goes down
- _id is always automatically indexed by MongoDB
- Too many indexes slow down the writing operation; explain() helps analyze
Full lesson
Code examples and quizzes
Full lessons, code examples, and quizzes are available to subscribers. 5 questions.