mongodb-schema-design — independently scanned and version-tracked by SaferSkills.
SaferSkills independently audited mongodb-schema-design (Agent Skill) and scored it 100/100 (green). The audit ran 55 deterministic rules across Security, Supply Chain, Maintenance, Transparency, and Community; it found 0 high-severity and 0 lower-severity findings. The full rule-by-rule trace and per-finding evidence are below. Free, methodology-open.
Findings & checks · 0 flagged
Every scanned point with the score it earned and what moved between them.
First recorded scan — no prior version to compare against.
The primary manifest — the file an agent reads to learn what this artifact does.
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.
Reference these guidelines when:
#### 1. Schema Anti-Patterns - 3 rules
into multiple collections is often an anti-pattern; consult this reference to validate whether this is the case.
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.
overlap or are not used by queries, to identify and remove unnecessary indexes that add overhead without benefit.
#### 2. Schema Fundamentals - 4 rules
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.
this reference when migrating from SQL or other normalized data to a document database like MongoDB.
new collections, or adding validation to existing collections, for example in response to finding inconsistent document structures or data quality issues.
hard 16MB limit, or when accesses are slower than expected as a result of large documents.
#### 3. Design Patterns - 11 rules
queries and audit trails
entities
larger than the rest, to prevent outliers from dominating memory and index costs
often when they are different types of the same base entity (e.g. different types of users or different types of products)
online migrations. Consult when encountering inconsistent document structures, or when planning a schema change that cannot be applied atomically.
for high-frequency time series data
"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
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.
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.
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.
$jsonSchema validator to catch invalid data at the database level (typechecks, required fields, enum constraints, array size limits). Start with validationLevel: "moderate" and validationAction: "warn" on existing collections, then tighten to strict/error.
unbounded arrays, large embedded binaries, deeply nested objects. Mitigate by moving unbounded data to separate collections and monitoring document sizes with $bsonSize.
| Relationship | Cardinality | Access Pattern | Recommendation |
|---|---|---|---|
| One-to-One | 1:1 | Always together | Embed |
| One-to-Few | 1:N (N < 100) | Usually together | Embed array |
| One-to-Many | 1:N (N > 100) | Often separate | Reference |
| Many-to-Many | M:N | Varies | Two-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.
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:
#### 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, 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:
mcp__mongodb__collection-schemamcp__mongodb__aggregatemcp__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 Type | MCP Tools | Action |
|---|---|---|
| Read (Safe) | find, aggregate, collection-schema, db-stats, count | I may run automatically to verify |
| Write (Requires Approval) | update-many, insert-many, create-collection | I will show the command and wait for your "yes" |
| Destructive (Requires Approval) | delete-many, drop-collection, drop-database | I will warn you and require explicit confirmation |
When I recommend schema changes or data modifications:
Your database, your decision. I'm here to advise, not to act unilaterally.
#### Working Together
If you're not sure about a recommendation:
We're a team-let's get this right together.
~30 seconds. Free. No account. Every finding cites a rule and a line of evidence.