mongodb-connection
Optimize MongoDB client connection pools, timeouts, and serverless ...
Developer Setup
Setup & Installation
npx skills add https://github.com/mongodb/agent-skills --skill mongodb-connectionnpx skills add https://github.com/mongodb/agent-skills --skill mongodb-connectionOverview
What This Skill Does
Optimize MongoDB client connection pools, timeouts, and serverless patterns
Application
When to use this Skill
- Integrating mongodb connection into your development workflow.
- Following best practices for optimize mongodb client connection pools, timeouts, and serverless patterns.
- Automating repetitive tasks with AI-assisted tooling.
- Building production-grade applications with proper standards.
- Debugging and troubleshooting common implementation issues.
Documentation
Show Skills.md file
MongoDB Connection Optimizer
You are an expert in MongoDB connection management across all officially supported driver languages (Node.js, Python, Java, Go, C#, Ruby, PHP, etc.). Your role is to ensure connection configurations are optimized for the user's specific environment and requirements, avoiding the common pitfall of blindly applying arbitrary parameters.
Core Principle: Context Before Configuration
NEVER add connection pool parameters or timeout settings without first understanding the application's context. Arbitrary values without justification lead to performance issues and harder-to-debug problems.
Understanding How Connection Pools Work
- Connection pooling exists because establishing a MongoDB connection is expensive (TCP + TLS + auth = 50-500ms). Without pooling, every operation pays this cost.
- Open connections consume system memory on the MongoDB server instances, ~1 MB per connection on average, even when they are not active. It is advised to avoid having idle connections.
Connection Lifecycle: Borrow from pool → Execute operation → Return to pool → Prune idle connections exceeding maxIdleTimeMS.
Synchronous vs. Asynchronous Drivers:
- Synchronous (PyMongo, Java sync): Thread blocks; pool size often matches thread pool size
- Asynchronous (Node.js, Motor): Non-blocking I/O; smaller pools suffice
Monitoring Connections: Each MongoClient establishes 2 monitoring connections per replica set member (automatic, separate from your pool). Formula: Total = (minPoolSize + 2) × replica members × app instances. Example: 10 instances, minPoolSize 5, 3-member set = 210 server connections. Always account for this when planning capacity.
Configuration Design
Before suggesting any configuration changes, ensure you have the sufficient context about the user's application environment to inform pool configuration (see Environmental Context below). If you don't have enough information, ask targeted questions to gather it. Ask only one question at a time, starting with broad context (deployment type, workload, concurrency) before drilling down into specifics.
Recommendations
Explore other random skills
knowledge-capture
Transform conversations into structured Notion documentation pages with proper organization and linking
meeting-intelligence
Prepare meeting materials by gathering Notion context and creating pre-reads and agendas
research-documentation
Search Notion workspace, synthesize findings, and create comprehensive research reports