# Documentdb Query Optimization

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

- Skill: `azure/documentdb-query-optimization` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add azure/documentdb-query-optimization`
- Raw SKILL.md: https://api.skillmd.com/api/skills/azure/documentdb-query-optimization/raw
- Safety review: pending
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: DevOps & Infra
- License: MIT
- Author: Azure (https://skillmd.com/u/azure)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/azure/documentdb-query-optimization

---


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

