# documentdb-query-optimization

Checks Azure DocumentDB queries with explain executionStats to confirm index use and catch collection scans.

Skill by Microsoft. Category: Data and backend.

## Install

Project (for this project only):

```sh
npx skills add azure/documentdb-agent-kit --skill documentdb-query-optimization
```

Works with: Claude Code, Codex CLI, Cursor, Antigravity, Copilot CLI, opencode.

Global (for every project on this machine):

```sh
npx skills add azure/documentdb-agent-kit --skill documentdb-query-optimization -g
```

Works with: Claude Code, Codex CLI, Cursor, Antigravity, Copilot CLI, opencode.

## Tags

- Runs on your computer: It runs as a program on your machine, with your access.

## Security audits

- Gen Agent Trust Hub: Pass
- Socket: Pass
- Snyk: Pass

Installs: 14. Installs counted by skills.sh. [Open on skills.sh](https://www.skills.sh/azure/documentdb-agent-kit/documentdb-query-optimization)

## Source

[Open the source](https://github.com/azure/documentdb-agent-kit/tree/HEAD/skills/query-optimization). Checked 2026-10-10. This summary may contain AI-generated text, so it can be wrong. Check the source before you rely on it.

## SKILL.md

````markdown
---
name: documentdb-query-optimization
description: Query and aggregation-pipeline optimization rules for Azure DocumentDB — using `explain("executionStats")` to verify index usage and avoid `COLLSCAN`. Use when reviewing a specific query, diagnosing a slow query, or validating that an index is actually being used. For full index-design workflow, see the `documentdb-query-optimizer` skill.
license: MIT
---

# Query & Aggregation Optimization — Azure DocumentDB

Best-practice rules for writing queries that can actually use indexes. For the full diagnostic workflow (explain output interpretation, ESR compound index design, covered queries, anti-patterns), see the `documentdb-query-optimizer` skill.

## Rules

- [query-explain-plan](query-explain-plan.md) — Use `explain("executionStats")` to verify index usage; watch `keysExamined` / `docsExamined` vs `nReturned`; avoid `COLLSCAN`.
````

- Previous: [documentdb-natural-language-querying](https://syn4pse.dev/terminal/documentdb-natural-language-querying.md)
- Next: [documentdb-query-optimizer](https://syn4pse.dev/terminal/documentdb-query-optimizer.md)
- [Terminal](https://syn4pse.dev/terminal.md)
- [Suggest a change](mailto:terminal@syn4pse.dev?subject=Terminal%20suggestion)
