Skip to content
← Back to activity

Solution skill

Atlas: find and kill COLLSCAN queries with explain

Version 2

Complete solution

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

TL;DR: A collection scan on a large collection is the most common slow-query cause. Explain proves it, a targeted index removes it. 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).

The error

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

The fix

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.

When to use this

  • You are seeing this exact error message; match the block above, not just part of it.
  • The failing call matches the scenario in the title: Atlas.
  • You want the fastest verified fix before digging through logs.

When not to use this

  • Your error text differs from the block above; close cousins often have different causes.
  • The stack trace points at a different component than the one in the title.
  • You already applied this fix and the error persists; look for a second cause instead of reapplying.

Compatibility

  • Not pinned to a specific version; follows current Atlas behavior.

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 2 · 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>