Official agent skill

Mongodb Schema Design

by mongodb in mongodb/agent-skills

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

OfficialApache-2.0Auto-check passedDatabases

Install Mongodb Schema Design

skills CLI
$ npx skills add mongodb/agent-skills --skill mongodb-schema-design -a claude-code

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

GitHub CLI
$ gh skill install mongodb/agent-skills mongodb-schema-design --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-schema-design .claude/skills/mongodb-schema-design && 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-schema-design
GitHub stars
190
Used in
2 other repos
Token cost
~3.4k tokens
SKILL.md length
1,616 words
Files
21 (incl. references)
Skills in repo
9
Repo updated
First seen
Licence
Apache-2.0

At a glance

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

  • Works in 3 steps: Schema Anti-Patterns - 3 rules → Schema Fundamentals - 4 rules → Design Patterns - 11 rules
  • Designing data models
  • SKILL.md covers When to Apply, Quick Reference, Key Principle and Embed/Reference Decision…, plus 2 more sections
  • Instructions only: no scripts, shell commands, URLs or credentials in SKILL.md

What it does

Mongodb Schema Design is an agent skill from mongodb/agent-skills, published by the product's own GitHub organization. MongoDB schema design patterns and anti-patterns. Use when designing data models, reviewing schemas, migrating from SQL, or troubleshooting performance issues caused by schema problems. Triggers on "design schema", "embed vs reference", "MongoDB data model", "schema review", "unbounded arrays", "one-to-many", "tree structure", "16MB limit", "schema validation", "JSON Schema", "time series", "schema migration", "polymorphic", "TTL", "data lifecycle", "archive", "index explosion", "unnecessary indexes"…

Its SKILL.md is about 3.4k tokens, which your agent loads only when the skill is triggered. The skill folder holds 21 other files, including reference files (for example `references/antipattern-excessive-lookups.md`, `references/antipattern-unnecessary-collections.md` and `references/antipattern-unnecessary-indexes.md`).

It sits in Databases, covering NoSQL databases, Database schema design and Forms and validation. It works with MongoDB 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

  • Designing data models
  • Reviewing schemas
  • Migrating from SQL
  • Troubleshooting performance issues caused by schema problems

Example prompts

  • “design schema”
  • “embed vs reference”
  • “MongoDB data model”
  • “/mongodb-schema-design”

Workflow steps

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

  1. Schema Anti-Patterns - 3 rules
  2. Schema Fundamentals - 4 rules
  3. Design Patterns - 11 rules

What it can do on your machine

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

  • Tool permissions

    Pre-approves nothing: there is no allowed-tools line, so your agent's usual permission prompts apply.

    From allowed-tools in the SKILL.md frontmatter.

  • Runs code

    No scripts in the folder and no shell commands in SKILL.md.

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

  • Network

    Links to these hosts (documentation or services it may open):

    • github.com

    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 Schema Design loads about 3.4k tokens when it runs, and up to ~30k if it reads all its reference files. Until then it costs about 144 tokens; SKILL.md has 1,616 words of instructions outside code blocks.

Always · name and description, kept in context so the agent knows when to use it
~144
When it runs · the whole SKILL.md, loaded when a task matches
~3.4k
With references · SKILL.md plus every file in references/, read only if the agent opens them
~30k

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 18b014e, republished under its Apache-2.0 licence (© mongodb). 1,616 words, ~3,407 tokens.

Download SKILL.mdSave it as .claude/skills/mongodb-schema-design/SKILL.md (or your agent's skills folder). This skill also uses 20 other files; get the full folder from GitHub.
name
mongodb-schema-design
description
MongoDB schema design patterns and anti-patterns. Use when designing data models, reviewing schemas, migrating from SQL, or troubleshooting performance issues caused by schema problems. Triggers on "design schema", "embed vs reference", "MongoDB data model", "schema review", "unbounded arrays", "one-to-many", "tree structure", "16MB limit", "schema validation", "JSON Schema", "time series", "schema migration", "polymorphic", "TTL", "data lifecycle", "archive", "index explosion", "unnecessary indexes", "approximation pattern", "document versioning".
license
Apache-2.0
metadata.version
1.0.0

MongoDB Schema Design

Data modeling patterns and anti-patterns for MongoDB, maintained by MongoDB. Bad schema is the root cause of most MongoDB performance and cost issues—queries and indexes cannot fix a fundamentally wrong model.

When to Apply

Reference these guidelines when:

  • Designing a new MongoDB schema from scratch
  • Migrating from SQL/relational databases to MongoDB
  • Reviewing existing data models for performance issues
  • Troubleshooting slow queries or growing document sizes
  • Deciding between embedding and referencing
  • Modeling relationships (one-to-one, one-to-many, many-to-many)
  • Implementing tree/hierarchical structures
  • Seeing Atlas Schema Suggestions or Performance Advisor warnings
  • Hitting the 16MB document limit
  • Adding schema validation to existing collections

Quick Reference

1. Schema Anti-Patterns - 3 rules
  • antipattern-unnecessary-collections - Splitting homogeneous data into multiple collections is often an anti-pattern; consult this reference to validate whether this is the case.
  • antipattern-excessive-lookups - When encountering overly normalized collections that reference each other or frequent and possibly slow $lookup operations, consult this reference to validate whether this is problematic and how to fix it.
  • antipattern-unnecessary-indexes - Consult this reference when indexes overlap or are not used by queries, to identify and remove unnecessary indexes that add overhead without benefit.
2. Schema Fundamentals - 4 rules
  • fundamental-embed-vs-reference - Consult this reference for approaches to modeling different types of relationships (1:1, 1:few, 1:many, many:many, tree/hierarchical data) and how to decide between embedding and referencing based on access patterns.
  • fundamental-document-model - Fundamentals of the document model. Consult this reference when migrating from SQL or other normalized data to a document database like MongoDB.
  • fundamental-schema-validation - Consult this reference when creating new collections, or adding validation to existing collections, for example in response to finding inconsistent document structures or data quality issues.
  • fundamental-document-size - Consult this reference when documents hit the hard 16MB limit, or when accesses are slower than expected as a result of large documents.
3. Design Patterns - 11 rules
  • pattern-approximation - Use approximate values for high-frequency counters
  • pattern-archive - Move historical data to separate/cold storage for performance
  • pattern-attribute - Collapse many optional fields into key-value attributes
  • pattern-bucket - Group time-series or IoT data into buckets
  • pattern-computed - Pre-calculate expensive aggregations
  • pattern-document-versioning - Track document changes to enable historical queries and audit trails
  • pattern-extended-reference - Cache frequently-accessed data from related entities
  • pattern-outlier - Handle collections in which a small subset of documents are much larger than the rest, to prevent outliers from dominating memory and index costs
  • pattern-polymorphic - Store different types of entities in the same collection, often when they are different types of the same base entity (e.g. different types of users or different types of products)
  • pattern-schema-versioning - Schema evolution, preventing drift, and safe online migrations. Consult when encountering inconsistent document structures, or when planning a schema change that cannot be applied atomically.
  • pattern-time-series-collections - Use native time series collections for high-frequency time series data
Access Pattern Analysis

Do not immediately recommend a pattern or schema change without understanding the broader context. Together with the user, analyze access patterns to identify pain points and opportunities for optimization.

Workflow

Step 1: Assess the environment Ask the user:

  • Is this a new design or is there a production database with existing access patterns to analyze?
  • If there is production data, is it on Atlas? If yes, what tier? (M0/M2/M5 vs M10+)

Step 2: Determine workload type Is the workload read-heavy, write-heavy, or balanced? This will influence which diagnostic sources are most relevant. Ask the user:

  • What's the primary workload for these collections — read-heavy (analytics, reports, searches), write-heavy (logging, IoT ingestion, frequent updates), or balanced?

Verify with db.serverStatus().opcounters.

Step 3: Work with the user to choose the best source(s) Recommend the best source(s) for their situation, explaining the tradeoffs. For schema design decisions, we often need to combine multiple sources for a complete picture.

Step 4: Proceed with analysis Only after source selection, fetch data or guide the user through analysis.

Sources
  • Query statistics - Returns runtime statistics for recorded queries showing query shapes and frequency. Limitation: Currently only captures read operations (pair with other sources for write patterns). Requires Atlas M10+ tier.
  • Atlas Slow Query Logs - Review slow queries (actual queries, not shapes) to identify performance bottlenecks. Captures all reads and writes. Requires Atlas M10+ tier.
  • Codebase - Examine actual queries in application code to understand access patterns, especially for new applications or with changing workloads. Can be used in conjunction with query stats for a more complete picture.
  • Natural language input - Ask the user to describe their typical queries and access patterns in natural language. Can be used as the only source or to supplement and validate other sources - the user might have contextual knowledge that is not reflected in the data or codebase.

Combining Query Stats and Slow Query Logs:

Use both together for comprehensive analysis:

  1. Query Stats → identify frequent access patterns (which queries run most often)
  2. Slow Query Logs → identify performance bottlenecks (which queries are slow)
  3. Focus schema optimization on queries that are both frequent AND slow (highest impact)

Key Principle

"Data that is accessed together should be stored together."

This is MongoDB's core philosophy. Embedding related data eliminates joins, reduces round trips, and enables atomic updates. Reference only when you must.

A core way to implement this philosophy is the fact that MongoDB exposes flexible schemas. This means you can have different fields in different documents, and even different structures. This allows you to model data in the way that best fits your access patterns, without being constrained by a rigid schema. For example, if different documents have different sets of fields, that is perfectly fine as long as it serves your application's needs. You can also use schema validation to enforce certain rules while still allowing for flexibility.

Another implication of the key principle is that information about the expected read and write workload becomes very relevant to schema design. If pieces of information from different entities are often queried or updated together, that means that prioritizing co-location of that data in the same document can lead to significant performance benefits. On the other hand, if certain pieces of information are rarely accessed together, it may make sense to store them separately to avoid loading more data than necessary.

Show full SKILL.md (614 more words)Show less
Schema Fundamentals Summary
  • Embed vs Reference: Choose embedding or referencing based on access patterns: embed when data is always accessed together (1:1, 1:few, bounded arrays, atomic updates needed); reference when data is accessed independently, relationships are many-to-many, or arrays can grow without bound.
  • Data accessed together stored together: MongoDB's core principle: design schemas around queries, not entities. Embed related data to eliminate cross-collection joins and reduce round trips. Identify your API endpoints/pages, list the data each returns, then shape documents to match those queries.
  • Embrace the document model: Don't recreate SQL tables 1:1 as MongoDB collections. Instead, denormalize joined tables into rich documents for single-query reads and atomic updates. When migrating from SQL, identify tables that are always joined together and merge them into single documents.
  • Schema validation: Use MongoDB's built-in $jsonSchema validator to catch invalid data at the database level (type checks, required fields, enum constraints, array size limits). Start with validationLevel: "moderate" and validationAction: "warn" on existing collections, then tighten to strict/error.
  • 16MB document limit: MongoDB documents cannot exceed 16MB—this is a hard limit, not a guideline. Common causes: unbounded arrays, large embedded binaries, deeply nested objects. Mitigate by moving unbounded data to separate collections and monitoring document sizes with $bsonSize.

Embed/Reference Decision Framework

RelationshipCardinalityAccess PatternRecommendation
One-to-One1:1Always togetherEmbed
One-to-Few1:N (N < 100)Usually togetherEmbed array
One-to-Many1:N (N > 100)Often separateReference
Many-to-ManyM:NVariesTwo-way reference

This is a rough guideline, and whether to embed or reference depends on your specific access patterns, data size, and read/write frequencies. Always verify with your actual workload.

How to Use

Each reference file listed above contains detailed explanations and code examples. Use the descriptions in the Quick Reference to identify which files are relevant to your current task.

Each reference file contains:

  • Brief explanation of why it matters
  • Incorrect code example with explanation
  • Correct code example with explanation
  • "When NOT to use" exceptions
  • Performance impact and metrics
  • Verification diagnostics

How These Rules Work

MongoDB MCP Integration

For automatic verification, connect the MongoDB MCP Server.

If the MCP server is running and connected, I can automatically run verification commands to check your actual schema, document sizes, array lengths, index usage, slow query logs, and more. This allows me to provide tailored recommendations based on your real data, not just code patterns.

⚠️ Security: Use --readOnly for safety. Remove only if you need write operations.

When connected, I can automatically:

  • Infer schema via mcp__mongodb__collection-schema
  • Measure document/array sizes via mcp__mongodb__aggregate
  • Check collection statistics via mcp__mongodb__db-stats
⚠️ Action Policy

I will NEVER execute write operations without your explicit approval.

Before any write or destructive operation via MCP, I will: (1) summarize the exact operation (collection, index/validator, estimated number of docs affected), and (2) ask for explicit confirmation (yes/no). I will not proceed on partial or ambiguous approvals.

Operation TypeMCP ToolsAction
Read (Safe)find, aggregate, collection-schema, db-stats, countI may run automatically to verify
Write (Requires Approval)update-many, insert-many, create-collectionI will show the command and wait for your "yes"
Destructive (Requires Approval)delete-many, drop-collection, drop-databaseI will warn you and require explicit confirmation

When I recommend schema changes or data modifications:

  1. I'll explain what I want to do and why
  2. I'll show you the exact command
  3. I'll wait for your approval before executing
  4. If you say "go ahead" or "yes", only then will I run it

Your database, your decision. I'm here to advise, not to act unilaterally.

Working Together

If you're not sure about a recommendation:

  1. Run the verification commands I provide
  2. Share the output with me
  3. I'll adjust my recommendation based on your actual data

We're a team—let's get this right together.

© 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

SKILL.md and 20 other files (references) in skills/mongodb-schema-design of mongodb/agent-skills.

  • SKILL.md
  • references/antipattern-excessive-lookups.md
  • references/antipattern-unnecessary-collections.md
  • references/antipattern-unnecessary-indexes.md
  • references/fundamental-document-model.md
  • references/fundamental-document-size.md
  • references/fundamental-embed-vs-reference.md
  • references/fundamental-schema-validation.md
  • references/pattern-approximation.md
  • references/pattern-archive.md
  • references/pattern-attribute.md
  • references/pattern-bucket.md
  • references/pattern-computed.md
  • references/pattern-document-versioning.md
  • references/pattern-extended-reference.md
  • references/pattern-outlier.md
  • references/pattern-polymorphic.md
  • references/pattern-schema-versioning.md
  • references/pattern-time-series-collections.md
  • references/source-query-stats.md
  • … and 1 more

Open the folder on GitHubat commit 18b014e

Used in 2 other repositories

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

Compare with similar skills

Mongodb Schema Design 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 Schema Design compared with similar skills
SkillStarsUsed inTokensAuto-checkLicenceRepo updated
Mongodb Schema Design this skillmongodb/agent-skills1902 repos~3.4kAutomated safety check: PassApache-2.0
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
DatabasesMicrock/ordinary-claude-skills403—~1.9kAutomated safety check: NotesMIT
Rhctlsaidake/rhctl106—~4kAutomated safety check: NotesApache-2.0

Similar skills

  • 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 3 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
  • Databases

    Microck/ordinary-claude-skills

    Work with MongoDB (document database, BSON documents, aggregation pipelines, Atlas cloud) and PostgreSQL (relational database, SQL queries, psql CLI, pgAdmin).

    403 GitHub stars~1.9k tokensUpdated 1 mo ago
    DatabasesAuto-check: notes
  • Rhctl

    saidake/rhctl

    Run and author rhctl CLI workflows and remote environment scripts under scripts/ (PostgreSQL, JetStream, Docker, Redis, MongoDB, AWS LocalStack, execute/upload/patch).

    106 GitHub stars~4k tokensUpdated 2 days ago
    DatabasesAuto-check: notes
  • Database Expert

    cin12211/orca-q

    Database performance optimization, schema design, query analysis, and connection management across PostgreSQL, MySQL, MongoDB, and SQLite with ORM integration.

    224 GitHub stars~2.8k tokensUpdated 16 days 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.

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

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

    190 GitHub starsUsed in 1 repo~3.3k tokens
    Auto-check passed
  • Official

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

    190 GitHub starsUsed in 1 repo~2.4k tokens
    Auto-check passed
  • Mongodb Connection

    mongodb/agent-skills

    Official

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

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

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

Works with

Categories

Questions about Mongodb Schema Design

What does Mongodb Schema Design do?

MongoDB schema design patterns and anti-patterns. An agent skill from mongodb/agent-skills. Mongodb Schema Design is an agent skill from mongodb/agent-skills, published by the product's own GitHub organization. MongoDB schema design patterns and anti-patterns.

When should I use Mongodb Schema Design?

Mongodb Schema Design fits situations like: designing data models; reviewing schemas; migrating from SQL; troubleshooting performance issues caused by schema problems.

How do I install Mongodb Schema Design in Claude Code?

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

How do I install Mongodb Schema Design in Codex?

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

Can I use Mongodb Schema Design 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-schema-design -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-schema-design, .gemini/skills/mongodb-schema-design, .github/skills/mongodb-schema-design and .opencode/skills/mongodb-schema-design in your project.

What does Mongodb Schema Design need to run?

SKILL.md names no scripts, command-line tools or credentials: Mongodb Schema Design is instructions for the agent only.

Does Mongodb Schema Design access the network?

SKILL.md names 1 domain. As links in the text: github.com. This is read from the text; nothing was executed.

Is Mongodb Schema Design 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 Schema Design use?

Mongodb Schema Design 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 Schema Design use?

About 3.4k tokens (SKILL.md is roughly 14k characters). Agents keep only the skill's name and description in context until a task matches; then they load SKILL.md in full. Its references folder adds about 27k tokens, read only when the agent opens those files.

What are the alternatives to Mongodb Schema Design?

Skills that share tags, products or a category with Mongodb Schema Design: Database Fundamentals (DanielPodolsky/ownyourcode, 290 stars), DB Sculptor (EliasOulkadi/shokunin, 114 stars), Discover Database (rand/cc-polymath, 181 stars) and Databases (Microck/ordinary-claude-skills, 403 stars). The comparison table on this page puts their stars, adoption, token cost, safety result and licence side by side.

Who maintains Mongodb Schema Design?

mongodb (a GitHub organization, an official publisher) maintains it in mongodb/agent-skills, which has 190 GitHub stars. The repository holds 9 skills in this directory. The repository was last updated on October 7, 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.