← MongoDB learning pathMongoDB · Module 5 of 10
Indexes
Speed up queries with indexes.
📖 Key ideas
- Without indexes, MongoDB scans every document (COLLSCAN).
- createIndex({ email: 1 }) speeds lookups by email.
- Unique indexes prevent duplicates: { unique: true }.
- Compound indexes cover multi-field queries.
- explain() shows if an index is used.
💡 Real-life example: An index is the index at the back of a textbook: jump straight to the page.
IndexStructure for fast lookups
COLLSCANFull collection scan
Compound indexIndex on several fields
explain()Shows query plan