# Kill COLLSCANs

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

## Diagnose

```js
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

```js
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.