Typorithm · medium

explain()

mongo-explainmongodbexplainixscancollscan
Saved on this device
Full lesson · 8 learning steps Open any exercise for focused practice
1

Step 1 of 8 · intro card

Learn explain()

0%

Indexes

explain("executionStats") shows how a query runs — look for an IXSCAN stage (index used) versus a COLLSCAN (full collection scan).

Append .explain("executionStats") to a find() to see the chosen plan plus runtime numbers like totalDocsExamined.

In the winning plan, an IXSCAN stage means an index drove the query; a COLLSCAN means MongoDB read every document.

A healthy query examines roughly as many documents as it returns; a COLLSCAN on a large collection is the classic signal you need an index.

01

IXSCAN = an index was used.

02

COLLSCAN = full collection scan, no index.

03

executionStats reports docs and keys examined.

db.users.find({ email: "a@b.com" }).explain("executionStats")

Read the implementation

Connect each part of the code to the concept before you type.

1. The query

explain() attaches to a normal find() and reports how the query would run.

db.users.find({ email: "a@b.com" })

2. Execution stats

The "executionStats" mode runs the plan and reports docs examined, keys examined, and time.

.explain("executionStats")

3. Verbosity mode

Verbosity ranges from "queryPlanner" (plan only) to "executionStats" (with runtime numbers).

"executionStats"

A complete learning loop

01

Understand

Read the concept map and follow the code breakdown.

02

Reconstruct

Type the implementation, repair mistakes and work through every recall exercise.

03

Verify

Use the final check without hints; revisit weak concepts in short practice sessions.

explain(): Lesson & Practice · Typorithm | ApplyDjinn