← ClaudeAtlas

public-mongodb-expert-baselisted

MongoDB 知识基座。覆盖 Document Model、Aggregation Pipeline、Indexes、Replica Sets、Change Streams。供 devlab-mongodb-usage 通过 extends 继承。
seed-forge/harness-ai-kit · ★ 22 · AI & Automation · score 74
Install: claude install-skill seed-forge/harness-ai-kit
# MongoDB Knowledge Base Foundational guidance for building applications with MongoDB. > **Source**: Adapted from [mongodb/agent-skills](https://github.com/mongodb/agent-skills) (schema-design + query-optimizer + connection). ## Document Model - Design documents around access patterns, not normalization. - Embed related data that's always read together (1:1, 1:few). - Reference (DBRef or manual ID) for data that grows unbounded or is accessed independently. - Use arrays for ordered collections; use sub-documents for named fields. - Avoid anti-patterns: unbounded arrays, massive documents (>16MB), excessive nesting. ## Schema Design Patterns | Pattern | Use for | |---------|---------| | Embedding | 1:1, 1:few relationships, always-read-together data | | Referencing | 1:many (unbounded), independent access | | Bucket | Time-series data (group by time window) | | Tree | Hierarchical data (materialized paths, nested sets) | | Outlier | Handle occasional large documents separately | | Extended Reference | Embed frequently accessed fields, reference the rest | ## Indexing - Index fields used in queries, sorts, and aggregation `$match`/`$sort` stages. - Compound index order matters: equality first, then range, then sort. - Use `explain()` to verify index usage (look for `IXSCAN`, avoid `COLLSCAN`). - Text indexes for full-text search; 2dsphere for geospatial queries. - TTL indexes for auto-expiring documents. - Monitor with `$indexStats` — drop unused indexes. ## Aggregation P