mongodb-architect
Architect-level MongoDB guidance — document modelling by access pattern, embed-versus-reference decisions, index and aggregation strategy, schema validation, and the unbounded-document traps that make Mongo slow or expensive. Use when designing or reviewing a MongoDB data model.
- License 许可
- MIT
- 最近更新
- 2026-11-13
- Stars
- ★ 0
- Forks
- 0
01 前言 Front Matter
- name
- mongodb-architect
- license
- MIT
- metadata
- { "crusor-path": "website-architect/database-engineering-architect/mongodb-architect", "crusor-domain": "website-architect", "crusor-origin": "original", "crusor-sources": "mongodb.com/docs/manual; mongodb.com/docs/manual/data-modeling", "crusor-triggers": "mongodb, mongo, documents, aggregation pipeline, embed, references, nosql, mongoose", "crusor-verified-on": "2026-10-30" }
- description
- Architect-level MongoDB guidance — document modelling by access pattern, embed-versus-reference decisions, index and aggregation strategy, schema validation, and the unbounded-document traps that make Mongo slow or expensive. Use when designing or reviewing a MongoDB data model.
- compatibility
- MongoDB 6/7+; any driver or ODM
03 SKILL.md 正文
MongoDB Architect
MongoDB is not "SQL without joins". It is a model where the document boundary is the atomic unit — so the schema follows the query, not the entity.
When to use
- Aggregates are read and written as a unit (order + lines, profile + settings).
- Shape varies by tenant or evolves fast, with query patterns known.
- Document-per-entity access dominates; joins are rare.
When NOT to use
- Multi-entity reporting, ad-hoc joins, strong relational integrity.
- Highly relational data or money/inventory requiring cross-document transactions at volume.
Decision 1 — Model by access pattern
| Relationship | Choose |
|---|---|
| read together, bounded size | embed |
| referenced by many, unbounded | reference |
| many-to-many with attributes | reference + lookup collection |
| unbounded growth (events, logs) | separate collection, time-bucketed |
- Never embed an array that can grow without limit (16 MB document cap and in-place update costs).
- Duplicate data is a decision with a sync owner, not an accident.
- Each collection is designed for the queries it serves; a second query shape may warrant a second collection (CQRS-style).
Decision 2 — Indexes
- Index for the actual query: equality fields, then sort field, then range.
- Compound index prefix rules apply the same as relational.
explain("executionStats"): watchtotalDocsExaminedvsnReturned.- TTL indexes for expiring data; partial indexes for hot subsets.
- Text search:
$textfor simple needs, Atlas Search for real relevance.
Decision 3 — Writes and consistency
- Single-document writes are atomic; multi-document transactions exist but are a design smell at high volume — restructure instead.
- Write concern: acknowledge majority for durability-critical writes.
- Read concern:
localfor speed,majorityfor correctness-sensitive reads. - Optimistic concurrency with a version field for contended updates.
Decision 4 — Validation and evolution
$jsonSchemavalidation on collections where shape matters.- Migrations are scripts run as deploys: backfill, dual-read, switch, clean up.
- Field renames are dual-write migrations, never in-place rewrites of a large collection.
Decision 5 — Aggregation discipline
$matchfirst, then$lookup— pipelines that start with lookups scan everything.$lookupon unindexed foreign fields is a collection scan per document.allowDiskUsehides a design problem; keep the pipeline in memory.- Materialise expensive aggregates into a read collection, refreshed on write.
Failure modes at scale
- Embedded arrays growing unbounded until documents hit the size cap.
$lookupjoins turning a 3 ms query into 900 ms.- No compound index for the main list query → collection scans under load.
- Transactions used per-request to emulate a relational schema.
- No validation → five shapes of the same document in one collection.
Verification receipts
- Model documented: embed vs reference per relationship, with size bounds.
explain("executionStats")for the top queries, index used.- Validation schema present on shape-critical collections.
- Unbounded-array audit: every array has a cap or an archive path.
- Write/read concern chosen per collection, documented.
04 同仓库更多 Skills
interaction-patterns-architect
Architect-level interaction design in code — choosing established patterns over invented ones, feedback and latency behaviour, destructive-action safeguards, navigation and overlay conventions, and the state model behind every interactive surface. Use when a screen has to behave, not just look.
design-system-ops-architect
Architect-level operation of a design system in code — token pipelines and versioning, component API and variant policy, the catalogue as the contract, adoption metrics, and the governance that stops a system from forking into three. Use when a component library must survive several teams.
design-handoff-architect
Architect-level design handoff — what must be specified before implementation starts, tokens over raw values, responsive and content-limit contracts, state matrices, and the review loop that catches drift between design and code. Use when a design is about to become code.
content-microcopy-architect
Architect-level UI content — where strings live, voice and terminology consistency, error and empty-state copy as part of the interface, translation-ready authoring, and the content model a product needs before it multiplies screens. Use when the words in the interface matter as much as the pixels.
ui-ux-implementation-architect
Architect-level direction for turning a design into working UI — the handoff contract, component ownership versus screen-level layout, interaction and state conventions, design QA gates, and the review habits that keep an implementation faithful without frozen pixels. Use before any specific UI implementation skill.
test-strategy-architect
Architect-level test strategy — allocating assertions across unit, integration, contract and end-to-end layers, designing for testability through dependency boundaries, fixture and data strategy, and the flake and coverage policies that keep a suite trustworthy. Use when defining how a codebase is tested.