🦀 ClawHub
MongoDB
by @ivangdavila
Design schemas, write queries, and configure MongoDB for consistency and performance.
TERMINAL
clawhub install mongodb📖 About This Skill
name: MongoDB slug: mongodb version: 1.0.1 description: Design MongoDB schemas with proper embedding, indexing, aggregation, and production-ready patterns. metadata: {"clawdbot":{"emoji":"🍃","requires":{"anyBins":["mongosh","mongo"]},"os":["linux","darwin","win32"]}}
When to Use
User needs MongoDB expertise — from schema design to production optimization. Agent handles document modeling, indexing strategies, aggregation pipelines, consistency patterns, and scaling.
Quick Reference
| Topic | File |
|-------|------|
| Schema design patterns | schema.md |
| Index strategies | indexes.md |
| Aggregation pipeline | aggregation.md |
| Production configuration | production.md |
Schema Design Philosophy
Document Size Traps
Array Traps
$push without $slice = unbounded growth; use $push: {$each: [...], $slice: -100}$lookup Traps
$lookup performance degrades with collection size—no index on foreign collection (until 5.0)$lookup per pipeline stage—nested lookups get complex and slow$lookup with pipeline (5.0+) can filter before joining—massive improvementIndex Strategy
{createdAt: 1}, {expireAfterSeconds: 86400}Consistency Traps
{w: "majority", readConcern: "majority"} for strongretryWrites: true in connection string—handles transient failures automaticallyRead Preference Traps
nearest for lowest latency—but may read stale dataprimary or session-based causal consistencyObjectId Traps
ObjectId.getTimestamp()—extract creation time without extra field_id for creation order without createdAtPerformance Mindset
explain("executionStats") shows actual execution—not just theoretical plantotalDocsExamined vs nReturned ratio should be ~1—otherwise index missingCOLLSCAN in explain = full collection scan—add appropriate indexIXSCAN + totalDocsExamined: 0—all data from indexAggregation Philosophy
$match), project early ($project)—reduce data volume ASAP$match at start can use indexes; $match after $unwind cannotCommon Mistakes
⚡ When to Use
User needs MongoDB expertise — from schema design to production optimization. Agent handles document modeling, indexing strategies, aggregation pipelines, consistency patterns, and scaling.