Source profileQuality 91/100

fcakyon/claude-codex-settings/plugins/mongodb-skills/skills/mongodb-schema-design/SKILL.md

mongodb-schema-design

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 ind

Source repository stars
961
Declared platforms
0
Static risk flags
0
Last source update
2026-08-04
Source checked
2026-08-04

Decision brief

What it does—and where it fits

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.

Best for

  • Designing a new MongoDB schema from scratch
  • Migrating from SQL/relational databases to MongoDB
  • Reviewing existing data models for performance issues

Not for

  • Tasks that require unconfirmed production actions or broad system permissions.
  • Environments where the pinned source and install steps cannot be inspected.

Compatibility matrix

Platform support, with evidence labels

PlatformStatusEvidenceWhat to check
CodexNot declaredNo explicit evidencePortability before use
Claude CodeNot declaredNo explicit evidencePortability before use
CursorNot declaredNo explicit evidencePortability before use
Gemini CLINot declaredNo explicit evidencePortability before use
Open the compatibility checker

Installation

Inspect first. Install second.

The source command is displayed only when detected. A safe inspection prompt is always available so your agent can explain every action before execution.

Source-detected install commandSource
npx skills add https://github.com/fcakyon/claude-codex-settings --skill "plugins/mongodb-skills/skills/mongodb-schema-design"
Safe inspection promptEditorial

Inspect the Agent Skill "mongodb-schema-design" from https://github.com/fcakyon/claude-codex-settings/blob/ccd2e764cc57ba1e8de4833615a04d540ba1295a/plugins/mongodb-skills/skills/mongodb-schema-design/SKILL.md at commit ccd2e764cc57ba1e8de4833615a04d540ba1295a. List every install step, command, network request, credential, file read/write, external action, and rollback step. Explain whether it fits my task. Do not install or execute anything until I approve.

Workflow

What the source asks the agent to do

  1. 01

    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+)

    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+)What's the primary workload for these collections — read-heavy (analytics, reports, searches), write-heavy (logging, IoT ingestion, frequent updates), or balanced?
  2. 02

    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.

    Brief explanation of why it mattersIncorrect code example with explanationCorrect code example with explanation
  3. 03

    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 r…

    Designing a new MongoDB schema from scratchMigrating from SQL/relational databases to MongoDBReviewing existing data models for performance issues
  4. 04

    Quick Reference

    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.

    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…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.
  5. 05

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

Permission review

Static risk signals and limitations

No configured static risk pattern was detected

This is not proof of safety. Runtime behavior, indirect dependencies, and hidden external systems are outside the static scan.

Evidence record

Why each signal appears

EvidenceSourceComputedTestedEditorial
SignalValueEvidence typeMeaning
Quality score91/100ComputedDocumentation, specificity, maintenance, and trust rules
Repository stars961SourceRepository attention, not individual Skill quality
Compatibility0 platformsSourceDeclared in the catalog source record
Usage guideautomated source guideEditorialGenerated or reviewed according to the visible evidence level

Pinned source

Provenance and original SKILL.md

Repository
fcakyon/claude-codex-settings
Skill path
plugins/mongodb-skills/skills/mongodb-schema-design/SKILL.md
Commit
ccd2e764cc57ba1e8de4833615a04d540ba1295a
License
Apache-2.0
Collected
2026-08-04
Default branch
main
View the original SKILL.md

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.

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.

Alternatives

Compare before choosing

Computed 100165

JasonColapietro/suede-creator-skills

suede-ab-testing

Suede-owned experimentation discipline for hypotheses, sample sizing, test duration, significance, and repeatable experiment programs. Use when comparing variants, deciding whether a result is reliable, or building an experiment backlog and cadence. NOT FOR: analytics instrumentation (use suede-analytics), post-click conversion diagnosis (use suede-site-alchemy), or writing the variant copy itself (use suede-copy).

Computed 1007

narrative-io/narrative-skills-marketplace

design-analysis

Translate a fuzzy analytical question into a rigorous investigation plan. Interrogates the ask, grounds the plan in the available data dictionary, applies analytical best practices, and produces a structured brief of query specifications for a downstream query-writing skill. Plans, does not write SQL. Use when: "why did X drop", "is there a relationship between A and B", "who are our highest-value customers", "what's driving the change in Y", "investigate this trend", "design an analysis for", "

Computed 97165

JasonColapietro/suede-creator-skills

suede-churn-prevention

Suede-owned retention discipline for voluntary and involuntary churn: cancel flows, pause paths, evidence-based save offers, failed-payment recovery, proactive signals, and win-back design. Use when diagnosing subscriber loss or designing a bounded retention intervention. NOT FOR: lifecycle-email production (use suede-emails), pricing architecture (use suede-pricing), paywall design (use suede-paywalls), or event instrumentation (use suede-analytics).

Computed 9632,606

K-Dense-AI/scientific-agent-skills

neuropixels-analysis

Analyze Neuropixels extracellular recordings end-to-end with SpikeInterface. Covers loading SpikeGLX/Open Ephys/NWB data, preprocessing, drift/motion correction, Kilosort4 (and CPU) spike sorting, quality metrics, and unit curation (threshold-based, model-based UnitRefine, and AI-assisted visual review). Use when working with Neuropixels 1.0/2.0 recordings, spike sorting, or extracellular electrophysiology analysis.