Official agent skill

Mongodb Natural Language Querying

by mongodb in mongodb/agent-skills

Generate read-only MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents.

OfficialApache-2.0Auto-check passedDatabases

Install Mongodb Natural Language Querying

skills CLI
$ npx skills add mongodb/agent-skills --skill mongodb-natural-language-querying -a claude-code

Project install by default; add -g for ~/.claude/skills/.

GitHub CLI
$ gh skill install mongodb/agent-skills mongodb-natural-language-querying --agent claude-code

Project scope by default; add --scope user for a personal install. Needs GitHub CLI 2.90.0 or later (public preview).

Manual copy
$ git clone --depth 1 https://github.com/mongodb/agent-skills.git skills-src && mkdir -p .claude/skills && cp -r skills-src/skills/mongodb-natural-language-querying .claude/skills/mongodb-natural-language-querying && rm -rf skills-src

Use ~/.claude/skills/ instead of .claude/skills for a personal install. The folder must contain SKILL.md.

Claude Code skills documentation · loads skills from .claude/skills/

Facts

Skill name
mongodb-natural-language-querying
GitHub stars
189
Used in
1 other repo
Token cost
~2.4k tokens
SKILL.md length
1,100 words
Files
1
Skills in repo
9
Repo updated
First seen
Licence
Apache-2.0

At a glance

Generate read-only MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents.

  • Works in 4 steps: Gather Context Using MCP Tools → Analyze Context and Validate Fields → Choose Query Type: Find vs Aggregation → …
  • The user asks to write
  • SKILL.md covers Query Generation Process, Best Practices, Schema Analysis and Sample Document Usage, plus 3 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Mongodb Natural Language Querying is an agent skill from mongodb/agent-skills, published by the product's own GitHub organization. Generate read-only MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents. Use this skill whenever the user asks to write, create, or generate MongoDB queries, wants to filter/query/aggregate data in MongoDB, asks "how do I query...", needs help with query syntax, or discusses finding/filtering/grouping MongoDB documents. Also use for translating SQL-like requests to MongoDB syntax. Does NOT handle Atlas Search ($search operator)…

Its SKILL.md is about 2.4k tokens, which your agent loads only when the skill is triggered. It is a single SKILL.md file with no bundled scripts.

It sits in Databases, covering NoSQL databases. It works with MongoDB, Model Context Protocol and SQL. The repository describes itself as: Use the official MongoDB Skills with your favorite coding agent to build faster. The licence is Apache-2.0.

When your agent uses it

  • The user asks to write
  • Generate MongoDB queries
  • Wants to filter/query/aggregate data in MongoDB
  • Asks how do I query...

Example prompts

  • “how do I query...”
  • “/mongodb-natural-language-querying”

Requirements

  • Pre-approved tools (allowed-tools): mcp__mongodb__*

Workflow steps

4 steps, taken from the step headings in SKILL.md.

  1. Gather Context Using MCP Tools
  2. Analyze Context and Validate Fields
  3. Choose Query Type: Find vs Aggregation
  4. Format Your Response

What it can do on your machine

Read from SKILL.md and the folder at commit c370a63. It shows what the files ask for, not the result of running them.

  • Tool permissions

    Pre-approves these tools, so the agent can use them without asking each time:

    • mcp__mongodb__*

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md (its code samples are json).

    From the folder's file list and the shell code blocks in SKILL.md.

  • Network

    No URLs in SKILL.md.

    From URLs in SKILL.md, links to its own repository left out.

  • Credentials

    Names no API keys, tokens, secrets or passwords.

    From names ending in _API_KEY, _TOKEN, _SECRET, _KEY or _PASSWORD in SKILL.md.

Context cost

Mongodb Natural Language Querying loads about 2.4k tokens when it runs. Until then it costs about 215 tokens; SKILL.md has 1,100 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~215
When it runs · the whole SKILL.md, loaded when a task matches
~2.4k

Estimates: characters ÷ 4, the usual rule of thumb; real counts depend on the model's tokenizer. Scripts and assets cost tokens only if the agent reads them.

Safety

Auto-check passed

The automated check found no risky patterns in SKILL.md.

Automated static check — not a guarantee. Review scripts before installing. It scans the text of SKILL.md for risky patterns (piping downloads into a shell, reading credential files, hidden Unicode, destructive commands); files beside SKILL.md are not scanned.

SKILL.md

The full file from mongodb/agent-skills at commit c370a63, republished under its Apache-2.0 licence (© mongodb). 1,100 words, ~2,407 tokens.

Download SKILL.mdSave it as .claude/skills/mongodb-natural-language-querying/SKILL.md (or your agent's skills folder).
name
mongodb-natural-language-querying
description
Generate read-only MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents. Use this skill whenever the user asks to write, create, or generate MongoDB queries, wants to filter/query/aggregate data in MongoDB, asks "how do I query...", needs help with query syntax, or discusses finding/filtering/grouping MongoDB documents. Also use for translating SQL-like requests to MongoDB syntax. Does NOT handle Atlas Search ($search operator), vector/semantic search ($vectorSearch operator), fuzzy matching, autocomplete indexes, or relevance scoring - use search-and-ai for those. Does NOT analyze or optimize existing queries - use mongodb-query-optimizer for that. Does NOT handle aggregation pipelines that involve write operations. Requires MongoDB MCP server.
allowed-tools
mcp__mongodb__*
license
Apache-2.0
metadata.version
1.0.0

MongoDB Natural Language Querying

You are an expert MongoDB read-only query and aggregation pipeline generator.

Query Generation Process

1. Gather Context Using MCP Tools

Required Information:

  • Database name and collection name (use mcp__mongodb__list-databases and mcp__mongodb__list-collections if not provided)
  • User's natural language description of the query

Fetch in this order:

  1. Indexes (for query optimization):

    mcp__mongodb__collection-indexes({ database, collection })
  2. Schema (for field validation):

    mcp__mongodb__collection-schema({ database, collection, sampleSize: 50 })
    • Returns flattened schema with field names and types
    • Includes nested document structures and array fields
  3. Sample documents (for understanding data patterns):

    mcp__mongodb__find({ database, collection, limit: 4 })
    • Shows actual data values and formats
    • Reveals common patterns (enums, ranges, etc.)
2. Analyze Context and Validate Fields

Before generating a query, always validate field names against the schema you fetched. MongoDB won't error on nonexistent field names - it will simply return no results or behave unexpectedly, making bugs hard to diagnose. By checking the schema first, you catch these issues before the user tries to run the query.

Also review the available indexes to understand which query patterns will perform best.

3. Choose Query Type: Find vs Aggregation

Prefer find queries over aggregation pipelines because find queries are simpler and easier for other developers to understand.

Use Find Query when:

  • Simple filtering on one or more fields
  • Basic sorting, limiting, or projecting specific fields
  • No need for grouping, complex transformations, or multi-stage processing

Use Aggregation Pipeline when the request requires:

  • Grouping or aggregation functions (sum, count, average, etc.)
  • Multiple transformation stages
  • Joins with other collections ($lookup)
  • Array unwinding or complex array operations
4. Format Your Response

Output queries using the user-requested language or driver syntax; if no language or expected format is supplied, always use MongoDB shell syntax (with unquoted keys and single quotes) for readability and compatibility with MongoDB tools.

Find Query Response:

json
{
  "query": {
    "filter": "{ age: { $gte: 25 } }",
    "projection": "{ name: 1, age: 1, _id: 0 }",
    "sort": "{ age: -1 }",
    "limit": "10"
  }
}

Aggregation Pipeline Response:

json
{
  "aggregation": {
    "pipeline": "[{ $match: { status: 'active' } }, { $group: { _id: '$category', total: { $sum: '$amount' } } }]"
  }
}

Best Practices

Query Quality
  1. Generate correct queries - Build queries that match user requirements, then check index coverage:
    • Generate the query to correctly satisfy all user requirements
    • After generating the query, check if existing indexes can support it
    • If no appropriate index exists, mention this in your response (user may want to create one)
    • Never use $where because it prevents index usage
    • Do not use $text without a text index
    • $expr should only be used when necessary (use sparingly)
  2. Avoid redundant operators - Never add operators that are already implied by other conditions:
    • Don't add $exists when you already have an equality or inequality check (e.g., status: "active" or age: { $gt: 25 } already implies the field exists)
    • Don't add overlapping range conditions (e.g., don't use both $gte: 0 and $gt: -1)
    • Each condition should add meaningful filtering that isn't already covered
  3. Project only needed fields - Reduce data transfer with projections
    • Add _id: 0 to the projection when _id field is not needed
  4. Validate field names against the schema before using them
  5. Use appropriate operators - Choose the right MongoDB operator for the task:
    • $eq, $ne, $gt, $gte, $lt, $lte for comparisons
    • $in, $nin for matching against a list of possible values (equivalent to multiple $eq/$ne conditions OR'ed together)
    • $and, $or, $not, $nor for logical operations
    • $regex for case-sensitive text pattern matching (prefer left-anchored patterns like /^prefix/ when possible, as they can use indexes efficiently)
    • $exists for field existence checks (prefer a: {$ne: null} to a: {$exists: true} to leverage available indexes)
    • $type for type matching
  6. Optimize array field checks - Use efficient patterns for array operations:
    • To check if an array is non-empty: use "arrayField.0": {$exists: true} instead of arrayField: {$exists: true, $type: "array", $ne: []}
    • Checking for the first element's existence is simpler, more readable, and more efficient than combining existence, type, and inequality checks
    • For matching array elements with multiple conditions, use $elemMatch
    • For array length checks, use $size when you need an exact count
Show full SKILL.md (483 more words)Show less
Aggregation Pipeline Quality
  1. Filter early - Use $match as early as possible to reduce documents
  2. Project at the end - Use $project at the end to correctly shape returned documents to the client
  3. Limit when possible - Add $limit after $sort when appropriate
  4. Use indexes - Ensure $match and $sort stages can use indexes:
    • Place $match stages at the beginning of the pipeline
    • Initial $match and $sort stages can use indexes if they precede any stage that modifies documents
    • After generating $match filters, check if indexes can support them
    • Minimize stages that transform documents before first $match
  5. Optimize $lookup - Consider denormalization for frequently joined data
Error Prevention
  1. Validate all field references against the schema
  2. Quote field names correctly - Use dot notation for nested fields
  3. Escape special characters in regex patterns
  4. Check data types - Ensure field values match field types from schema
  5. Geospatial coordinates - MongoDB's GeoJSON format requires longitude first, then latitude (e.g., [longitude, latitude] or {type: "Point", coordinates: [lng, lat]}). This is opposite to how coordinates are often written in plain English, so double-check this when generating geo queries.

Schema Analysis

When provided with sample documents, analyze:

  1. Field types - String, Number, Boolean, Date, ObjectId, Array, Object
  2. Field patterns - Required vs optional fields (check multiple samples)
  3. Nested structures - Objects within objects, arrays of objects
  4. Array elements - Homogeneous vs heterogeneous arrays
  5. Special types - Dates, ObjectIds, Binary data, GeoJSON

Sample Document Usage

Use sample documents to:

  • Understand actual data values and ranges
  • Identify field naming conventions (camelCase, snake_case, etc.)
  • Detect common patterns (e.g., status enums, category values)
  • Estimate cardinality for grouping operations
  • Validate that your query will work with real data

Error Handling

If you cannot generate a query:

  1. Explain why - Missing schema, ambiguous request, impossible query
  2. Ask for clarification - Request more details about requirements
  3. Suggest alternatives - Propose different approaches if available
  4. Provide examples - Show similar queries that could work

Example Workflow

User Input: "Find all active users over 25 years old, sorted by registration date"

Your Process:

  1. Check schema for fields: status, age, registrationDate or similar
  2. Verify field types match the query requirements
  3. Generate query based on user requirements
  4. Check if available indexes can support the query
  5. Suggest creating an index if no appropriate index exists for the query filters

Generated Query:

json
{
  "query": {
    "filter": "{ status: 'active', age: { $gt: 25 } }",
    "sort": "{ registrationDate: -1 }"
  }
}

Managing Context Size

Fetching large or numerous sample documents wastes context and can degrade query quality.

Adjust sample count by schema width:

  • < 30 fields: limit: 4 (default)
  • 30–80 fields: limit: 2
  • 80–150 fields: limit: 1
  • 150+ fields: limit: 1 with a projection of only the fields relevant to the user's query

Preview large array fields and strings:

  • If schema documents contains arrays, use $slice: 3 in the sample projection to cap array size. Limit string fields to 100 characters with $substr in the sample projection to prevent excessively long values from consuming context.

© mongodb, Apache-2.0. Rendered from Markdown: HTML in the file is shown as text, images as links, and headings moved down two levels. Raw file

Files

Just SKILL.md in skills/mongodb-natural-language-querying of mongodb/agent-skills.

Open the folder on GitHubat commit c370a63

Used in 1 other repository

We found 5 copies of this SKILL.md (exact, near-identical or edited) in other folders, from 1 other GitHub owner. This page covers the copy in mongodb/agent-skills, which our catalogue first saw on October 7, 2026.

Compare with similar skills

Mongodb Natural Language Querying next to the 5 skills that share the most tags, products or categories with it. Stars are the repository's; “used in” counts other GitHub owners with a copy.

Mongodb Natural Language Querying compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Mongodb Natural Language Querying this skillmongodb/agent-skills1891 repos~2.4kAutomated safety check: PassApache-2.0
Mindsdb MCP SkillLeoYeAI/openclaw-master-skills2.2k—~2.5kAutomated safety check: PassMIT
Azure Storagemicrosoft/GitHub-Copilot-for-Azure2552 repos~1.3kAutomated safety check: PassMIT
Database FundamentalsDanielPodolsky/ownyourcode2901 repos~1.6kAutomated safety check: PassMIT
DB SculptorEliasOulkadi/shokunin114—~3.1kAutomated safety check: NotesMIT
Discover Databaserand/cc-polymath181—~2kAutomated safety check: PassMIT

Similar skills

  • Mindsdb MCP Skill

    LeoYeAI/openclaw-master-skills

    MindsDB MCP服务器交互技能,用于通过自然语言查询和操作200+企业级数据源。当用户需要查询数据库、分析数据、创建AI模型、连接数据源(MySQL、PostgreSQL、MongoDB、Excel、CSV、Gmail、Slack等)、执行SQL查询、进行数据预测、构建知识库(RAG)、智能问答、文档检索或任何与数据库交互的任务时使用此技能。即使没有明确提到MindsDB,只要涉及数据库操…

    2.2k GitHub stars~2.5k tokensUpdated 2 mo ago
    DatabasesAuto-check passed
  • Azure Storage

    microsoft/GitHub-Copilot-for-Azure

    Official

    Azure Storage Services including Blob Storage, File Shares, Queue Storage, Table Storage, and Data Lake.

    255 GitHub starsUsed in 2 repos~1.3k tokens
    DatabasesAuto-check passed
  • Database Fundamentals

    DanielPodolsky/ownyourcode

    Reviews schema design, SQL queries, ORM patterns. An agent skill from DanielPodolsky/ownyourcode.

    290 GitHub starsUsed in 1 repo~1.6k tokens
    DatabasesAuto-check passed
  • DB Sculptor

    EliasOulkadi/shokunin

    Design database schemas with Prisma/Drizzle, PostgreSQL index strategy (B-tree, GIN, GiST, BRIN, Hash), query optimization (EXPLAIN ANALYZE), migration safety (expand/contract, zero-downtime), and…

    114 GitHub stars~3.1k tokensUpdated 5 days ago
    DatabasesAuto-check: notes
  • Discover Database

    rand/cc-polymath

    Automatically discover database skills when working with SQL, PostgreSQL, MongoDB, Redis, database schema design, query optimization, migrations, connection pooling, ORMs, or database selection.

    181 GitHub stars~2k tokensUpdated 7 mo ago
    DatabasesAuto-check passed
  • Query Expert

    jamesrochabrun/skills

    Master SQL and database queries across multiple systems. An agent skill from jamesrochabrun/skills.

    216 GitHub stars~4.3k tokensUpdated 8 mo ago
    DatabasesAuto-check passed

More from mongodb/agent-skills

All 9 skills in this repo
  • Mongodb Query Optimizer

    mongodb/agent-skills

    Official

    Help with MongoDB query optimization and indexing. An agent skill from mongodb/agent-skills.

    189 GitHub starsUsed in 2 repos~2.6k tokens
    Auto-check passed
  • Review Skill

    mongodb/agent-skills

    Official

    Review a proposed Agent Skill for structural validity and content quality before publishing.

    189 GitHub stars~1.5k tokensUpdated today
    Auto-check: notes
  • Mongodb MCP Setup

    mongodb/agent-skills

    Official

    Guide users through configuring key MongoDB MCP server options.

    189 GitHub starsUsed in 1 repo~3.3k tokens
    Auto-check passed
  • Mongodb Schema Design

    mongodb/agent-skills

    Official

    MongoDB schema design patterns and anti-patterns. An agent skill from mongodb/agent-skills.

    189 GitHub starsUsed in 2 repos~3.4k tokens
    Auto-check passed
  • Mongodb Connection

    mongodb/agent-skills

    Official

    Optimize MongoDB client connection configuration (pools, timeouts, patterns) for any supported driver language.

    189 GitHub starsUsed in 1 repo~3.5k tokens
    Auto-check passed
  • Mongodb Search And AI

    mongodb/agent-skills

    Official

    Guides MongoDB users through implementing and optimizing Atlas Search (full-text), Vector Search (semantic), and Hybrid Search solutions.

    189 GitHub starsUsed in 1 repo~1.7k tokens
    Auto-check passed

Categories

Questions about Mongodb Natural Language Querying

What does Mongodb Natural Language Querying do?

Generate read-only MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents. Mongodb Natural Language Querying is an agent skill from mongodb/agent-skills, published by the product's own GitHub organization. Generate read-only MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents.

When should I use Mongodb Natural Language Querying?

Mongodb Natural Language Querying fits situations like: the user asks to write; generate MongoDB queries; wants to filter/query/aggregate data in MongoDB; asks how do I query...

How do I install Mongodb Natural Language Querying in Claude Code?

Run `npx skills add mongodb/agent-skills --skill mongodb-natural-language-querying -a claude-code`. Or copy the skill folder (skills/mongodb-natural-language-querying in mongodb/agent-skills) into .claude/skills/mongodb-natural-language-querying in your project. Claude Code loads it when a task matches its description.

How do I install Mongodb Natural Language Querying in Codex?

Run `npx skills add mongodb/agent-skills --skill mongodb-natural-language-querying -a codex`. Or copy the skill folder (skills/mongodb-natural-language-querying in mongodb/agent-skills) into .agents/skills/mongodb-natural-language-querying in your project. Codex loads it when a task matches its description.

Can I use Mongodb Natural Language Querying in Cursor, Gemini CLI or GitHub Copilot?

Cursor, Gemini CLI, GitHub Copilot and OpenCode also load SKILL.md folders. With the skills CLI, run `npx skills add mongodb/agent-skills --skill mongodb-natural-language-querying -a cursor` (or -a gemini-cli, github-copilot or opencode for the others). To copy it by hand, put the folder in .cursor/skills/mongodb-natural-language-querying, .gemini/skills/mongodb-natural-language-querying, .github/skills/mongodb-natural-language-querying and .opencode/skills/mongodb-natural-language-querying in your project.

What does Mongodb Natural Language Querying need to run?

SKILL.md names no scripts, command-line tools or credentials: Mongodb Natural Language Querying is instructions for the agent only. Its frontmatter pre-approves these tools: mcp__mongodb__*.

Does Mongodb Natural Language Querying access the network?

SKILL.md contains no URLs. Any network use would come from the scripts or tools the agent runs. This is read from the text; nothing was executed.

Is Mongodb Natural Language Querying safe to install?

Our automated static check of SKILL.md found no risky patterns, such as piping downloads into a shell, reading credential files or hidden Unicode. It is not a guarantee. Review the folder before installing.

What licence does Mongodb Natural Language Querying use?

Mongodb Natural Language Querying is published under the Apache-2.0 licence (declared in SKILL.md). It allows redistribution, so the full SKILL.md is shown on this page.

How many tokens does Mongodb Natural Language Querying use?

About 2.4k tokens (SKILL.md is roughly 9.6k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full.

What are the alternatives to Mongodb Natural Language Querying?

Skills that share tags, products or a category with Mongodb Natural Language Querying: Mindsdb MCP Skill (LeoYeAI/openclaw-master-skills, 2.2k stars), Azure Storage (microsoft/GitHub-Copilot-for-Azure, 255 stars), Database Fundamentals (DanielPodolsky/ownyourcode, 290 stars) and DB Sculptor (EliasOulkadi/shokunin, 114 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Mongodb Natural Language Querying?

mongodb (a GitHub organization, an official publisher) maintains it in mongodb/agent-skills, which has 189 GitHub stars. The repository holds 9 skills in this directory. The repository was last updated on October 10, 2026.

Source: mongodb/agent-skills on GitHub. Facts on this page come from the repository at the commit we read; the author's words are quoted as theirs.