Content & privacy
Databases · INTERVIEW GUIDE

MongoDB & Mongoose

Document modeling, aggregation, indexes, and consistency.

Practice this topic
Filters
4 questions

How do indexes help, and what do they cost?

MongoDB & Mongoose·Indexes & query plans

An index is an extra data structure that helps the database find matching records without inspecting every document. Reads can become much faster, but inserts, updates and deletes must maintain the relevant indexes. Indexes are most useful when their fields and order match important query patterns.

Intermediate2 min read

What index types should I know?

MongoDB & Mongoose·Indexes & query plans

MongoDB offers different index types because equality lookup, array search, text search, uniqueness and expiry have different needs. A compound index orders several fields together, while a partial index includes only documents matching a condition. TTL indexes support eventual cleanup rather than precise scheduling.

Intermediate2 min read

What is the ESR rule?

MongoDB & Mongoose·Indexes & query plans

ESR stands for Equality, Sort and Range, a common starting point for ordering fields in a compound index. Equality fields narrow the relevant index region, sort fields can let MongoDB read in the desired order, and range fields constrain intervals. It is a guideline that must be checked against selectivity and the query plan.

Intermediate2 min read

What should I check in explain?

MongoDB & Mongoose·Indexes & query plans

explain shows how MongoDB plans a query, and execution-statistics modes also show what work was performed. It helps distinguish an efficient index lookup from broad scanning, sorting or excessive document fetching. The goal is to understand why the query does work, not simply whether an index was selected.

Intermediate2 min read

Difficulty is an editorial estimate. Completion means you chose to mark a question as understood.