documentdb-connection
Optimize MongoDB client connection configuration (pools, timeouts, patterns) for Azure DocumentDB.
Skill by khelanmodi
Install
Works with Claude Code, Claude apps, Codex, Cursor, Gemini CLI, GitHub Copilot, VS Code, OpenCode, Goose, Windsurf. Read the repository before you give any tool access to your data.
npx agentmarket install skill/khelanmodi-documentdb-connection
Asks which of your tools to add it to (Claude Code, Codex, Cursor, VS Code, Windsurf, Gemini CLI, Claude Desktop) and shows the change first. See https://agentmart.dev/cli.
Get the weekly diff
The weekly diff: one email a week with new agent tools, notable updates and grade changes, plus security alerts for tools you follow. Double opt-in, one-click unsubscribe.
About
Use cases: backend, cloud
Reviews
Write a reviewNo reviews yet. Installed it? Reviews come from verified installers only. How reviews work
Permissions: not checked yet.
What's inside
- Skill name
documentdb-connection- Description
- Optimize MongoDB client connection configuration (pools, timeouts, patterns) for Azure DocumentDB. Use this skill when working on functions that instantiate or configure a MongoDB client (e.g., calling `connect()`), configuring connection pools, troubleshooting connection errors (ECONNREFUSED, timeouts, pool exhaustion), optimizing connection-related performance issues. Includes scenarios like building serverless functions, creating API endpoints, optimizing high-traffic applications, or debugging connection failures.
- License
- MIT
- Instructions
- 253 lines in SKILL.md · view on GitHub
Agent Skills spec issues
- name: "documentdb-connection" does not match folder "connection"
Files (1)
- SKILL.md
SKILL.md (first lines)
# DocumentDB Connection Optimizer
You are an expert in MongoDB connection management for Azure DocumentDB
across all officially supported driver languages (Node.js,
Python, Java, Go, C#, etc.). Your role is to ensure connection configurations
are optimized for the user's specific environment and requirements.
## 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 memory on the server, ~1 MB per connection on
average, even when idle. 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. Formula:
`Total = (minPoolSize + 2) × replica members × app instances`.
## Azure DocumentDB Connection Specifics
### Connection String Format
```
mongodb+srv://<username>:<password>@<cluster-name>.mongocluster.cosmos.azure.com/?tls=true&authMechanism=SCRAM-SHA-256&retryWrites=true
```
Or the non-SRV format:
```
mongodb://<username>:<password>@<cluster-name>.mongocluster.cosmos.azure.com:10255/?tls=true&authMechanism=SCRAM-SHA-256&retryWrites=true
```
### TLS Is Required
Azure DocumentDB **always requires TLS**. Ensure:
- `tls=true` in the connection string
- If using self-signed certificates in development, configure the CA
certificate path in the driver
### Authentication
- Default mechanism: `SCRAM-SHA-256`
- Credentials are managed through the Azure portal (cluster's connection
settings)
## Configuration Design
**Before suggesting any configuration changes**, ensure you have sufficient
context about the user's application environment. If you don't have enough
information, ask targeted questions. Ask **only one question at a time**.
### Configuration Scenarios
**General best practices:**
- Create client once only and reuse across application
- Don't manually close connections unless shutting down
- Max pool size must exceed expected concurrency
- Use timeouts to keep only the required connections ready
- Use default max pool size (100) unless you have specific needs
#### Scenario: Serverless Environments (Azure Functions, AWS Lambda)
**Critical pattern:** Initialize client OUTSIDE handler/function scope to enable
connection reuse across warm invocations.
| Parameter | Value | Reasoning |
|-----------|-------|-----------|
| `maxPoolSize` | 3–5 | Each function instance has its own pool |
| `minPoolSize` | 0 | Prevent maintaining unused connections |
| `maxIdleTimeMS` | 10–30s | Release unused connections quickly |
| `connectTimeoutMS` | >0 | Set to longest expected network latency |
| `socketTimeoutMS` | >0 | Ensure sockets are always closed |
```javascript
// Azure Functions — initialize outside handler
const { MongoClient } = require('mongodb');
const client = new MongoClient(process.env.DOCUMENTDB_URI, {
maxPoolSize: 5,
minPoolSize: 0,
maxIdleTimeMS: 30000,
});
module.exports = async function (context, req) {
const db = client.db('mydb');
const result = await db.collection('items').findOne({});
context.res = { body: result };
};
```
#### Scenario: Traditional Long-Running Servers (OLTP)
| Parameter | Value | Reasoning |
|-----------|-------|-----------|
| `maxPoolSize` | 50+ | Based on peak concurrent requests |
| `minPoolSize` | 10–20 | Pre-warmed connections for traffic spikes |
| `maxIdleTimeMS` | 5–10min | Stable servers benefit from persistent connections |
| `connectTimeoutMS` | 5–10s | Fail fast on connection issues |
| `socketTimeoutMS` | 30s | Prevent hanging queries |
| `serverSelectionTimeoutMS` | 5s | Quick failover |
#### Scenario: OLAP / Analytical Workloads
| Parameter | Value | Reasoning |
|-----------|-------|-----------|From khelanmodi/documentdb-agent-kit, MIT.
More from khelanmodi/documentdb-agent-kit
- 0.406score
documentdb-mcp-setup
khelanmodi
Guide users through configuring the DocumentDB MCP server for Azure DocumentDB.
SkillDFreshness: DClaude Code +9 - 0.401score
documentdb-cluster-sharding
khelanmodi
Cluster sizing and sharding guidance for Azure DocumentDB — choosing M-tier (M10–M200+), when to scale vertically vs horizontally, and how to pick a shard key…
SkillDFreshness: DClaude Code +9 - 0.401score
documentdb-high-availability
khelanmodi
High availability and disaster-recovery best practices for Azure DocumentDB — enabling in-region HA (99.99% SLA) and adding active-passive cross-region…
SkillDFreshness: DClaude Code +9
Signals
- Stars
- 0
- Forks
- 1
- Open issues
- 2
- Last commit (this folder)
- Apr 21, 2026 (6 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- First seen
- Oct 24, 2026
- Last checked
- Oct 24, 2026
- Source
- GitHubgithub-graphql
Same skill elsewhere
Copies of this SKILL.md published by others; search shows only one of them.
More from khelanmodi
- 0.406score
documentdb-mcp-setup
khelanmodi
Guide users through configuring the DocumentDB MCP server for Azure DocumentDB.
SkillDFreshness: DClaude Code +9 - 0.401score
documentdb-cluster-sharding
khelanmodi
Cluster sizing and sharding guidance for Azure DocumentDB — choosing M-tier (M10–M200+), when to scale vertically vs horizontally, and how to pick a shard key…
SkillDFreshness: DClaude Code +9 - 0.401score
documentdb-high-availability
khelanmodi
High availability and disaster-recovery best practices for Azure DocumentDB — enabling in-region HA (99.99% SLA) and adding active-passive cross-region…
SkillDFreshness: DClaude Code +9
Cite this page
documentdb-connection skill. Agent Mart. https://agentmart.dev/skills/khelanmodi-documentdb-connection (last updated 2026-10-24)