用 Codex 或 Claude 帮你安装 复制这段 Prompt,粘贴到 Codex、Claude 或其他助手里,让它检查 Skill 页面并帮你完成安装。
直接命令不会经过审查 Prompt;运行前请先检查来源。
npx skills add https://github.com/mikailustuner/OmniRule --skill mongodb-patterns命令会保持在同一行。复制前请横向滚动并检查完整内容。
想先保存到本地?可下载 SkillsMP 当前能够提供的文件。
正在显示 SKILL.md
基于 SOC 职业分类
| name | mongodb-patterns |
| description | MongoDB Patterns: Schema design, aggregation pipeline, indexing, data modeling. |
| triggers | {"extensions":[".ts"],"keywords":["MongoDB","mongoose","aggregation","atlas","NoSQL","collection","document","pipeline"]} |
| auto_load_when | Working with MongoDB queries or schemas |
| agent | infra-specialist |
| tools | ["Read","Write","Bash"] |
Focus: Document modeling, query optimization, aggregation
Embedded (when):
├── One-to-few (order + line items)
├── Data queried together
├── No growth limit (embedded array)
└── Consistency important
Reference (when):
├── One-to-many (author + books)
├── Data grows unbounded
├── Different access patterns
└── Need to query independently
Use MongoDB when:
├── Flexible schema needed
├── JSON-like documents
├── Hierarchical data
├── Rapid prototyping
├── Large data volumes
└── Horizontal scaling needed
Avoid when:
├── Strong consistency required (ACID)
├── Complex joins
├── Fixed schema
└── Small data, simple queries
Pipeline stages:
├── $match - filter documents
├── $project - shape output
├── $group - aggregate
├── $sort - order results
├── $limit - pagination
└── $lookup - join collections
Performance: Place filters early
Index types:
├── Single field - simple queries
├── Compound - multi-field queries
├── Multikey - arrays
├── Text - search
└── Hashed - sharding
Avoid: Over-indexing (write overhead)
Pattern: Polymorphic
├── Same collection, different docs
└── Type field distinguishes
Pattern: Bucket
├── Time-series data
└── Groups by time window
Pattern: Attribute
├── Many optional fields
└── Single array query
Shard key selection:
├── High cardinality
├── Even distribution
├── Common query filter
└── Avoid monotonically increasing
Shard patterns:
├── Range-based (contiguous)
└── Hash-based (random)
Query optimization:
├── Project only needed fields
├── Use covered queries
├── Limit result set
├── Avoid $regex where possible
Aggregation:
├── Use $limit early
├── Stage ordering matters
└── Allow use of indexes
(End of file - 79 lines)
❌ No indexes on query fields — full collection scans
✅ explain() every slow query; add compound indexes
❌ Storing large blobs (images, files) in documents
✅ Use GridFS or object storage; store URLs in MongoDB
❌ Deeply nested arrays updated with positional $ on multiple levels
✅ Flatten nested structures; split into separate collections if complex
❌ Schema-less = schema-free thinking
✅ Define Mongoose schema or Zod validation — enforce shape
❌ Reading entire documents to get 1 field
✅ Projection: { name: 1, email: 1, _id: 0 }
| Operation | Pattern | Note |
|---|---|---|
| Find + filter | find({field: value}) + index | Always index query fields |
| Partial update | $set, $inc, $push | Never replace whole doc for updates |
| Aggregation | $match early, $project late | Reduce pipeline cardinality first |
| Transactions | session.withTransaction() | Requires replica set |
| TTL expiry | createIndex + expireAfterSeconds | Auto-cleanup |
| Full-text search | $text index | Or Atlas Search for advanced |