Skip to main content

Indexing for MongoDBs

MongoDB indexing creates ordered data structures, usually B-trees, so queries find documents without scanning a whole collection. Index types include single field, compound, multikey, text, geospatial, TTL and partial. This unit in the Performance stage teaches how to create them and verify their use through explain plans.

Stage: Performance · Part of the MongoDB roadmap · Last reviewed 19 November 2026

What to learn in Indexing

Indexing interview questions

How do you check whether a MongoDB query uses an index?

Run explain('executionStats') on the query. A winning plan with IXSCAN means an index is used, while COLLSCAN means a full scan. Compare totalDocsExamined and nReturned, because a large gap shows the index is not selective enough.

Does the order of fields in a compound index matter?

Yes. A compound index supports queries that use a leftmost prefix of its fields, and its order affects sorting. A common rule is to put equality fields first, then sort fields, then range fields, matching how the query filters and sorts.

Where Indexing fits in the MongoDB roadmap

Indexing belongs to the Performance stage (intermediate level), which takes about 12 hours. Indexes and aggregation.

Back to the full MongoDB roadmap