MongoDB — document modelling (embed vs reference) by access patterns, indexes and the ESR rule, aggregation pipelines, transactions and write concerns, schema validation, sharding keys, change streams. Use for MongoDB data modelling and queries (MongoDB, document model, aggregation, sharding, indexes).
Installs into .claude/skills of the current project.
Sponsors
SSkills DirectorySkills Directory
Know which skills are safe — weekly.
SSkills DirectorySkills Directory
Is that skill safe to install?
Are you the author of Mongodb?
Add the live security badge to your README. It updates with every re-scan.
[](https://www.skillsdirectory.com/skills/vectora-os-mongodb)
---
name: mongodb
description: MongoDB — document modelling (embed vs reference) by access patterns, indexes and the ESR rule, aggregation pipelines, transactions and write concerns, schema validation, sharding keys, change streams. Use for MongoDB data modelling and queries (MongoDB, document model, aggregation, sharding, indexes).
metadata:
category: data
---
# MongoDB
## Purpose
Model documents around access patterns while keeping data consistent.
**Use when:** MongoDB schemas and queries.
**Not for:** relational workloads better served by SQL.
## Inputs
- Access patterns, data sizes.
## Outputs
- Document models, indexes, validation rules.
## Read first
- [Project Brain](../../../project-brain/README.md) — `npm run brain -- query "mongodb"` for prior decisions, patterns and anti-patterns.
## Steps
1. **Model.** Embed data read together; reference unbounded or shared data.
Done when no unbounded arrays.
2. **Index.** Compound indexes by Equality-Sort-Range.
Done when queries are covered or indexed.
3. **Validate.** JSON schema validation on collections.
Done when invalid writes rejected.
4. **Consistency.** Set write concern majority for critical data; transactions sparingly.
Done when durability settings documented.
## Best practices
- Explain plans for every hot query.
- Pick shard keys with high cardinality and even distribution.
## Common mistakes
- Schemaless chaos.
- Monotonic shard keys.
## Example
Order with embedded line items, referenced customer; index `{customerId:1, createdAt:-1}`.
## Reusable prompt
```text
Apply the MongoDB skill (.agents/skills/mongodb/SKILL.md).
Context: {{task card or question; links to PRD, ADRs, code paths}}
Constraints: {{approved thresholds, deadlines, allowed files}}
Model the documents from access patterns and define indexes, validation and write concerns.
Return: Document models, indexes, validation rules..
Cite evidence (file:line, command output, source) for every claim; list open questions separately.
```