
Mongodb
Design MongoDB schemas, write queries and aggregation pipelines, and wire Mongoose with sensible connection defaults.
Overview
MongoDB is an agent skill for the Build phase that guides MongoDB and Mongoose schema, query, aggregation, and performance work.
Install
npx skills add https://github.com/hoodini/ai-agents-skills --skill mongodbWhat is this skill?
- Covers native MongoDB driver CRUD patterns with TypeScript (insert, find, update, delete)
- Documents Mongoose connect options: maxPoolSize 10, serverSelectionTimeoutMS 5000, socketTimeoutMS 45000
- Includes connection lifecycle handlers and SIGINT graceful shutdown for Mongoose
- Triggers on MongoDB, Mongoose, aggregation pipeline, Atlas, and NoSQL design tasks
- npm quick start: `mongodb` and `mongoose` packages
- Mongoose connect example sets maxPoolSize to 10
- serverSelectionTimeoutMS 5000 and socketTimeoutMS 45000 in the documented connect options
Adoption & trust: 1.4k installs on skills.sh; 222 GitHub stars; 3/3 security scanners passed (skills.sh audits).
What problem does it solve?
You need a document database layer but your agent keeps generating naive queries and connection code without pooling or shutdown handling.
Who is it for?
Indie APIs and SaaS backends on Node/TypeScript choosing MongoDB or Mongoose for flexible document models.
Skip if: Relational-only stacks (Postgres with strict SQL migrations) or teams that already enforce an internal DBA style guide the skill would override.
When should I use this skill?
Designing schemas, writing queries, building aggregation pipelines, or optimizing performance; triggers on MongoDB, Mongoose, NoSQL, aggregation pipeline, document database, MongoDB Atlas.
What do I get? / Deliverables
You get driver and Mongoose snippets and patterns aligned to SKILL.md best practices for schemas, pipelines, and operational connection setup.
- Schema and query patterns
- Driver or Mongoose connection setup
- Aggregation and CRUD code aligned to best practices
Recommended Skills
Journey fit
How it compares
Procedural MongoDB guidance in SKILL.md form—not an MCP server that executes queries against your cluster.
Common Questions / FAQ
Who is mongodb for?
Solo developers and agent-assisted teams building backends that store data in MongoDB or Mongoose on Node and TypeScript.
When should I use mongodb?
Use it in Build → Backend when designing schemas, writing queries, building aggregation pipelines, optimizing performance, or wiring Atlas/Mongoose connections.
Is mongodb safe to install?
The skill is documentation-style; review the Security Audits panel on this page and never paste production URIs or secrets into untrusted agent sessions.
SKILL.md
READMESKILL.md - Mongodb
# MongoDB & Mongoose Build and query MongoDB databases with best practices. ## Quick Start ```bash npm install mongodb mongoose ``` ### Native Driver ```typescript import { MongoClient, ObjectId } from 'mongodb'; const client = new MongoClient(process.env.MONGODB_URI!); const db = client.db('myapp'); const users = db.collection('users'); // Connect await client.connect(); // CRUD Operations await users.insertOne({ name: 'Alice', email: 'alice@example.com' }); const user = await users.findOne({ email: 'alice@example.com' }); await users.updateOne({ _id: user._id }, { $set: { name: 'Alice Smith' } }); await users.deleteOne({ _id: user._id }); ``` ### Mongoose Setup ```typescript import mongoose from 'mongoose'; await mongoose.connect(process.env.MONGODB_URI!, { maxPoolSize: 10, serverSelectionTimeoutMS: 5000, socketTimeoutMS: 45000, }); // Connection events mongoose.connection.on('connected', () => console.log('MongoDB connected')); mongoose.connection.on('error', (err) => console.error('MongoDB error:', err)); mongoose.connection.on('disconnected', () => console.log('MongoDB disconnected')); // Graceful shutdown process.on('SIGINT', async () => { await mongoose.connection.close(); process.exit(0); }); ``` ## Schema Design ### Basic Schema ```typescript import mongoose, { Schema, Document, Model } from 'mongoose'; interface IUser extends Document { email: string; name: string; password: string; role: 'user' | 'admin'; profile: { avatar?: string; bio?: string; }; createdAt: Date; updatedAt: Date; } const userSchema = new Schema<IUser>({ email: { type: String, required: [true, 'Email is required'], unique: true, lowercase: true, trim: true, match: [/^\S+@\S+\.\S+$/, 'Invalid email format'], }, name: { type: String, required: true, trim: true, minlength: 2, maxlength: 100, }, password: { type: String, required: true, select: false, // Never return password by default }, role: { type: String, enum: ['user', 'admin'], default: 'user', }, profile: { avatar: String, bio: { type: String, maxlength: 500 }, }, }, { timestamps: true, // Adds createdAt, updatedAt toJSON: { transform(doc, ret) { delete ret.password; delete ret.__v; return ret; }, }, }); // Indexes userSchema.index({ email: 1 }); userSchema.index({ createdAt: -1 }); userSchema.index({ name: 'text', 'profile.bio': 'text' }); // Text search const User: Model<IUser> = mongoose.model('User', userSchema); ``` ### Embedded Documents vs References ```typescript // ✅ Embed when: Data is read together, doesn't grow unbounded const orderSchema = new Schema({ customer: { name: String, email: String, address: { street: String, city: String, country: String, }, }, items: [{ product: String, quantity: Number, price: Number, }], total: Number, }); // ✅ Reference when: Data is large, shared, or changes independently const postSchema = new Schema({ title: String, content: String, author: { type: Schema.Types.ObjectId, ref: 'User', required: true, }, comments: [{ type: Schema.Types.ObjectId, ref: 'Comment', }], }); // Populate references const post = await Post.findById(id) .populate('author', 'name email') // Select specific fields .populate({ path: 'comments', populate: { path: 'author', select: 'name' }, // Nested populate }); ``` ### Virtuals ```typescript const userSchema = new Schema({ firstName: String, lastName: String, }); // Virtual field (not stored in DB) userSchema.virtual('fullName').get(function() { return `