From db-mongodb
Use when implementing MongoDB code with frameworks — enforces patterns for Mongoose (schemas, middleware, virtuals, populate), Motor (async cursors), MongoDB .NET Driver (BSON, LINQ), and migrate-mongo (migration scripts)
How this skill is triggered — by the user, by Claude, or both
Slash command
/db-mongodb:mongodb-frameworksThe summary Claude sees in its skill listing — used to decide when to auto-load this skill
- Always define `collection` option explicitly
collection option explicitlytimestamps: true for automatic createdAt/updatedAtlean() for read-only queries (returns plain objects, not Mongoose documents)validate → save → remove (document middleware)find → findOne → findOneAndUpdate (query middleware)aggregate (aggregate middleware)const paymentSchema = new Schema({ amount: Number, currency: String });
const Payment = mongoose.model('Payment', paymentSchema);
const CreditCardPayment = Payment.discriminator('CreditCard',
new Schema({ cardNumber: String, expiry: String }));
const BankTransfer = Payment.discriminator('BankTransfer',
new Schema({ accountNumber: String, routingNumber: String }));
to_list(length=N) with bounded length — never to_list(length=None) on large collectionsmotor.motor_asyncio.AsyncIOMotorClient for async operationsmaxPoolSize, minPoolSize, maxIdleTimeMScodec_options for automatic type conversionpublic class OrderRepository
{
private readonly IMongoCollection<Order> _collection;
public OrderRepository(IMongoDatabase database)
{
_collection = database.GetCollection<Order>("orders");
}
public async Task<Order?> GetByIdAsync(string id)
{
return await _collection.Find(o => o.Id == id).FirstOrDefaultAsync();
}
public async Task CreateAsync(Order order)
{
await _collection.InsertOneAsync(order);
}
}
var results = await _collection.AsQueryable()
.Where(o => o.Status == OrderStatus.Pending)
.OrderByDescending(o => o.CreatedAt)
.Take(20)
.ToListAsync();
up and downdb.collection() not model imports (framework-agnostic)add-customer-status-index, backfill-email-verifiednpx 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.