From db-mongodb
Use when writing or reviewing MongoDB code — enforces document design patterns (embed vs reference), schema validation, aggregation pipelines, indexing strategies (ESR rule), change streams, transactions, and security best practices
How this skill is triggered — by the user, by Claude, or both
Slash command
/db-mongodb:mongodb-codingThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- camelCase, descriptive, plural where appropriate
orders, orderItems, userSessions, auditLogs| Pattern | Use When | Example |
|---|---|---|
| Embed (subdocument) | 1:1 or 1:few, data always read together | Order → items array |
| Reference (ObjectId) | 1:many, many:many, data read independently | Order → customerId ref |
| Bucket | Time-series, high-volume events | Group events by hour/day |
| Outlier | Mostly small arrays, rare large ones | Most users have <10 addresses |
// Single collection for polymorphic types
{ type: "creditCard", cardNumber: "****1234", expiry: "12/26" }
{ type: "bankTransfer", accountNumber: "****5678", routingNumber: "****9012" }
additionalProperties: false cautiously (breaks additive migrations)db.orders.aggregate([
{ $match: { status: { $in: ["confirmed", "shipped"] } } },
{ $unwind: "$items" },
{ $group: {
_id: "$items.productId",
totalQuantity: { $sum: "$items.quantity" },
totalRevenue: { $sum: { $multiply: ["$items.price", "$items.quantity"] } }
}},
{ $sort: { totalRevenue: -1 } },
{ $limit: 10 }
]);
$match as early as possible to reduce documents in pipeline$project after $match to reduce document size$lookup with let and pipeline for complex joins$group on unindexed fields// Equality, Sort, Range — in that order
db.orders.createIndex({ status: 1, createdAt: -1, total: 1 });
db.products.createIndex({ name: "text", description: "text" });
db.sessions.createIndex({ expiresAt: 1 }, { expireAfterSeconds: 0 });
const session = client.startSession();
try {
session.startTransaction();
await orders.insertOne(order, { session });
await inventory.updateOne(
{ productId: order.items[0].productId },
{ $inc: { quantity: -order.items[0].quantity } },
{ session }
);
await session.commitTransaction();
} catch (error) {
await session.abortTransaction();
throw error;
} finally {
session.endSession();
}
const changeStream = orders.watch([
{ $match: { operationType: { $in: ["insert", "update"] } } }
]);
changeStream.on("change", (change) => {
console.log("Order changed:", change.documentKey._id);
});
const ops = items.map(item => ({
updateOne: {
filter: { _id: item._id },
update: { $set: { price: item.newPrice } },
upsert: false
}
}));
await collection.bulkWrite(ops, { ordered: false });
npx claudepluginhub gagandeepp/software-agent-teams --plugin db-mongodbGuides completion of development work by verifying tests, detecting environment, and presenting structured options for merge, PR, or cleanup.
Enforces test-driven development: write failing test first, then minimal code to pass. Use when implementing features or bugfixes.
Guides creation and editing of skills using test-driven development with pressure scenarios and subagents to verify agent compliance.