**TL;DR:** Slow endpoint, unknown cause. The symptom to cause path runs through the Query Profiler and Performance Advisor to a suggested index, verified with explain. Confirm Run the query shape with explain("executionStats") in mongosh. Fix Create the suggested index.

## The error

```text
an endpoint or job is slow and you suspect the database.
```

## The fix

# Slow queries: profiler to index

Symptom: an endpoint or job is slow and you suspect the database.

## Diagnose

1. Atlas UI: Performance Advisor. It lists slow query shapes grouped by pattern, with suggested indexes. This is only on M10+ clusters.
2. Cross-check with the Query Profiler (same area): it shows slow operations with key stats for the last few days, no extra cost.
3. Pick the worst shape by total time (frequency x avg duration), not the single slowest one-off.

## Confirm

Run the query shape with `explain("executionStats")` in mongosh. Look at `totalDocsExamined` vs `nReturned`. A big ratio means the query scans far more than it returns: missing or wrong index.

## Fix

Create the suggested index. The Performance Advisor can create it directly from the UI (one at a time), or run the `createIndex` in mongosh. Keep read/write ratio in mind: every index taxes writes.

## Verify

Re-run `explain`: `totalDocsExamined` should collapse toward `nReturned`, and the stage should be IXSCAN. Then watch the Performance Advisor over the next day to confirm the shape dropped off the slow list.

## 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.