Skip to content
Learn Netverks

Lesson

Step 14/36 39% through track

indexes-mongodb

Indexes in MongoDB

Last reviewed May 28, 2026 Content v20260528
Track mode
none
Means
Read / quiz
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Indexes in MongoDB: document modeling, query operators, and aggregation patterns for MongoDB.

COLLSCAN on hot APIs is a production incident—compound indexes must match filter + sort shape.

You will apply Indexes in MongoDB in contexts like: Slow API list endpoints, admin search, and ops firefighting on COLLSCAN alerts.

Copy JavaScript shell queries from each lesson into mongosh or MongoDB Atlas Data Explorer—inspect matched documents and explain plans. The in-browser lab (execution_profile: none) ships later; mongosh is the practice path now. Also check explain executionStats for IXSCAN vs COLLSCAN.

When you can explain the previous lesson's ideas without copying example queries verbatim.

Indexes speed queries and enforce uniqueness. Default _id index exists on every collection.

Single-field index

db.orders.createIndex({ customerId: 1 })
db.orders.createIndex({ status: 1, createdAt: -1 })
db.orders.getIndexes()

Practice: Run on practice in mongosh.

Unique index

db.users.createIndex({ email: 1 }, { unique: true })

Explain recap

db.orders.find({ customerId: 'c-42' }).explain('executionStats')

Look for IXSCAN vs COLLSCAN and totalDocsExamined.

Important interview questions and answers

  1. Q: Index trade-off?
    A: Faster reads, slower writes and more disk.
  2. Q: Compound index order?
    A: Equality fields first, then sort range—matches query shape.

Self-check

  1. Create index on email unique.
  2. What does COLLSCAN mean?

Tip: Index foreign keys used in $lookup and frequent find filters.

Interview prep

COLLSCAN?
Full collection scan—slow on large data without index.
Unique index?
Enforces uniqueness on indexed field(s).

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • IXSCAN goal?
  • Unique email?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump