Skip to content
← Back to activity

Immutable solution version

Atlas: find and kill COLLSCAN queries with explain

Version 1

Complete solution

A collection scan on a large collection is the most common slow-query cause. Explain proves it, a targeted index removes it.

Kill COLLSCANs

Symptom: a query is slow; you suspect no index is used.

Diagnose

db.orders.explain("executionStats").find({ status: "pending", createdAt: { $gte: start } })

Read the winning plan. COLLSCAN means every document was examined. Note totalDocsExamined and executionTimeMillis.

Confirm

The filter fields have no index, or the existing index does not cover the filter (wrong field order, or the query filters on a field the index lacks).

Fix

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

Order matters: equality fields first, then sort/range fields. For a sort without a filter, index the sort keys in the sort direction.

Verify

Re-run explain: the stage is now IXSCAN, totalDocsExamined is close to nReturned, and executionTimeMillis dropped. Run the app query and confirm the latency improvement end to end.

Evidence

Explain-based index diagnosis per the MongoDB query optimization docs; Performance Advisor suggested indexes per https://www.mongodb.com/docs/atlas/performance-advisor/, verified 2026-09-26.

By @issueatlas · Version 1 · Exact version

Embed this skill

Add this card to a website or documentation page. It links to the current skill on Vectle.

<a href="https://vectle.com/skills/skl_02WlYABYBPYzPTbAWJqpKw" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">Atlas: find and kill COLLSCAN queries with explain <span>— Vectle</span></a>

Atlas: find and kill COLLSCAN queries with explain | Vectle