Skip to content

/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",

shell
$ npx -y skills add fcakyon/claude-codex-settings --skill mongodb-schema-design --agent claude-code

How it fires

How this skill gets triggered: by you, by Claude, or both.

  • Fires itselfAuto-invocation. Claude auto-loads it when your prompt matches the work.
  • You can call itInvoke it directly when you want it.
  • Slash command/mongodb-schema-design
How auto-invocation works

Context preview

The summary Claude sees to decide when to auto-load this skill.

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",

SKILL.md

mongodb-schema-design.SKILL.md
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](references/antipattern-unnecessary-collections.md) - Splitting homogeneous data into multiple collections is often an anti-pattern; consult this reference to validate whether this is the case.
  • [antipattern-excessive-lookups](references/antipattern-excessive-lookups.md) - 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](references/antipattern-unnecessary-indexes.md) - 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](references/fundamental-embed-vs-reference.md) - 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](references/fundamental-document-model.md) - 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](references/fundamental-schema-validation.md) - 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](references/fundamental-document-size.md) - 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](references/pattern-approximation.md) - Use approximate values for high-frequency counters
  • [pattern-archive](references/pattern-archive.md) - Move historical data to separate/cold storage for performance
  • [pattern-attribute](references/pattern-attribute.md) - Collapse many optional fields into key-value attributes
  • [pattern-bucket](references/pattern-bucket.md) - Group time-series or IoT data into buckets
  • [pattern-computed](references/pattern-computed.md) - Pre-calculate expensive aggregations
  • [pattern-document-versioning](references/pattern-document-versioning.md) - Track document changes to enable historical queries and audit trails
  • [pattern-extended-reference](references/pattern-extended-reference.md) - Cache frequently-accessed data from related entities
  • [pattern-outlier](references/pattern-outlier.md) - 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](references/pattern-polymorphic.md) - 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](references/pattern-schema-versioning.md) - 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](references/pattern-time-series-collections.md) - 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,

Read more
Read it on GitHub ↗

Showing the first part of this file.

Ships withclaude-codex-settings

Battle-tested Claude Code, OpenAI Codex, Cursor configs, plugins, hooks and agents with Kimi, MiniMax and GLM API support.

Get the whole plugin, auto-invoked
Stats
955
Stars
0
Views
83
Forks
Active
Maintenance
Python
Language
Apache-2.0
License
7h ago
Last commit
1y ago
Created

Repo: fcakyon/claude-codex-settings

Other skills on claude-codex-settings.