mongodb-natural-language-querying
Generate read-only MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents.
Skill by mongodbOfficial
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/mongodb-mongodb-natural-language-querying
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: backend, data, writing, agent-building
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/mongodb-natural-language-querying
Tools it pre-approves 1
From allowed-tools in SKILL.md: the agent may use these without asking you each time.
mcp__mongodb__*
What's inside
- Skill 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.
- License
- Apache-2.0
- Allowed tools
- mcp__mongodb__*
- Metadata
- version: 1.0.0
- Instructions
- 188 lines in SKILL.md · view on GitHub
Files (1)
- SKILL.md
SKILL.md (first lines)
# 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
### 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 dataFrom mongodb/agent-skills, Apache-2.0.
More from mongodb/agent-skills
- 0.794score
mongodb-search-and-ai
mongodbOfficial
Covers everything about search in MongoDB: Atlas Search (full-text), Vector Search (semantic), and Hybrid Search.
SkillAFreshness: A★ 190Claude Code +9 - 0.785score
mongodb-qe-size-estimation
mongodbOfficial
Estimates the storage and memory impact of encrypting fields in collections with Queryable Encryption (QE) enabled.
SkillAFreshness: A★ 190Claude Code +9 - 0.691score
mongodb-connection
mongodbOfficial
Optimize MongoDB client connection configuration (pools, timeouts, patterns) for any supported driver language.
SkillCFreshness: C★ 190Claude Code +9 - 0.691score
mongodb-schema-design
mongodbOfficial
MongoDB schema design patterns and anti-patterns.
SkillCFreshness: C★ 190Claude Code +9 - 0.691score
mongodb-query-optimizer
mongodbOfficial
Help with MongoDB query optimization and indexing.
SkillCFreshness: C★ 190Claude Code +9 - 0.691score
mongodb-atlas-stream-processing
mongodbOfficial
Manages MongoDB Atlas Stream Processing (ASP) workflows.
SkillCFreshness: C★ 190Claude Code +9 - 0.685score
mongodb-mcp-setup
mongodbOfficial
Guide users through configuring key MongoDB MCP server options.
SkillCFreshness: C★ 190Claude Code +9 - 0.616score
review-skill
mongodbOfficial
Review a proposed Agent Skill for structural validity and content quality before publishing.
SkillDFreshness: D★ 190Claude Code +9
Signals
- Stars
- 190
- Forks
- 42
- Open issues
- 0
- Last commit (this folder)
- Jul 20, 2026 (3 months ago)
- Last release
- Mar 25, 2026 (7 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- Version
- 1.0.0
- License
- Apache-2.0
- Repository
- github.com/mongodb/agent-skills
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Same skill elsewhere
Copies of this SKILL.md published by others; search shows only one of them.
- 0.357score
mongodb-natural-language-querying
mongodbOfficial
Generate read-only MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents.
SkillCFreshness: C★ 190Claude Code +9 - 0.357score
mongodb-natural-language-querying
mongodbOfficial
Generate read-only MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents.
SkillCFreshness: C★ 190Claude Code +9
More from mongodb
- 0.794score
mongodb-search-and-ai
mongodbOfficial
Covers everything about search in MongoDB: Atlas Search (full-text), Vector Search (semantic), and Hybrid Search.
SkillAFreshness: A★ 190Claude Code +9 - 0.785score
mongodb-qe-size-estimation
mongodbOfficial
Estimates the storage and memory impact of encrypting fields in collections with Queryable Encryption (QE) enabled.
SkillAFreshness: A★ 190Claude Code +9 - 0.691score
mongodb-schema-design
mongodbOfficial
MongoDB schema design patterns and anti-patterns.
SkillCFreshness: C★ 190Claude Code +9 - 0.691score
mongodb-connection
mongodbOfficial
Optimize MongoDB client connection configuration (pools, timeouts, patterns) for any supported driver language.
SkillCFreshness: C★ 190Claude Code +9 - 0.691score
mongodb-atlas-stream-processing
mongodbOfficial
Manages MongoDB Atlas Stream Processing (ASP) workflows.
SkillCFreshness: C★ 190Claude Code +9 - 0.691score
mongodb-query-optimizer
mongodbOfficial
Help with MongoDB query optimization and indexing.
SkillCFreshness: C★ 190Claude Code +9
Cite this page
mongodb-natural-language-querying skill. Agent Mart. https://agentmart.dev/skills/mongodb-mongodb-natural-language-querying (last updated 2026-10-24)