mongodb-query-optimizer

Analyze MongoDB query shapes and recommend compound indexes from explain plans.

Updated Aug 27, 2026
One-click install
npx skills add https://github.com/jeremylasne92-hue/siteweb2 --skill mongodb-query-optimizer
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: mongodb-query-optimizer
Source: https://github.com/jeremylasne92-hue/siteweb2/tree/main/.agents/skills/mongodb-query-optimizer
Command: npx skills add https://github.com/jeremylasne92-hue/siteweb2 --skill mongodb-query-optimizer

SYSTEM DOCUMENTATION & REQUIREMENTS

💡 This Skill includes references (resource) components.

What problem does it solve?

This Skill helps diagnose slow MongoDB queries and reduce resource usage by identifying inefficient query shapes, missing or suboptimal indexes, and aggregation pipeline anti-patterns so teams can improve latency and throughput.

Core Features & Use Cases

  • Explain plan analysis: Run explain() to detect COLLSCANs, in-memory sorts, and examine keys/documents examined versus returned.
  • Index recommendations: Propose compound indexes following equality→sort→range (ERS) rules and identify opportunities for covered queries.
  • Atlas and MCP integration: Use Atlas Performance Advisor and slow query logs when Atlas API or MCP connection is available; fall back to query-shape advice when not.
  • Aggregation and update guidance: Load aggregation-optimization and update-query references for pipeline-specific or oplog-efficient update suggestions.

Quick Start

Ask "Why is this query slow?" and provide the query, database name, collection name, and optionally a MongoDB connection string or Atlas project/cluster identifiers so the skill can run explain and suggest indexes.

Frequently Asked Questions about mongodb-query-optimizer

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I optimize slow MongoDB queries and reduce latency?

MongoDB query optimization analyzes query shapes and indexes to reduce latency by detecting COLLSCANs and in-memory sorts, then proposing compound indexes following equality→sort→range rules to lower resource consumption.

Why is my MongoDB query slow and how do I read the explain plan?

Slow MongoDB queries are diagnosed by running explain() to examine keys and documents examined versus returned, identifying collection scans, in-memory sorts, and aggregation pipeline anti-patterns causing performance bottlenecks.

How do I create the right compound index for a MongoDB query?

Create compound MongoDB indexes by following equality→sort→range rules, prioritizing equality fields first, then sort fields, then range fields, while identifying opportunities for covered queries to minimize document fetches.

Can I use Atlas Performance Advisor to diagnose slow MongoDB queries?

Atlas Performance Advisor and slow query logs are supported when you provide Atlas project and cluster credentials or a MongoDB connection string, allowing direct analysis of collection indexes and query execution stats.

What do I need to provide to analyze a MongoDB aggregation pipeline?

Provide the query shape, database name, and collection name to analyze MongoDB aggregation pipelines, optionally including a connection string to run live explain plans and load aggregation optimization references.

Does this work without a live MongoDB connection string?

Yes, MongoDB query optimization falls back to query-shape advice when a connection string or Atlas credentials are unavailable, providing index recommendations and pipeline guidance based on the query structure alone.