documentdb-connection
Optimize MongoDB client connection configuration (pools, timeouts, patterns) for Azure DocumentDB.
Skill by AzureOfficial
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/azure-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
What this skill can do and what it asks for, from its SKILL.md. Checked Oct 25, 2026.
- Tools
- No tools found
- Secrets
- None asked for
- Install scripts
- None found
Network hosts it talks to 1
codeload.github.com· found in install command
Files it touches
~/.claude/skills/documentdb-connection
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
- 260 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 `MongoClient`, Java sync): Thread blocks; pool size
often matches thread pool size
- **Asynchronous** (Node.js, PyMongo `AsyncMongoClient`): Non-blocking I/O;
smaller pools suffice
> **Python async note:** Use PyMongo's native `AsyncMongoClient` (PyMongo
> 4.9+), **not** Motor. MongoDB announced Motor's deprecation in May 2024 in
> favor of PyMongo's built-in async API; Motor receives only critical fixes
> through May 2026 and is end-of-life after that. New Python async code on
> Azure DocumentDB should import `from pymongo import AsyncMongoClient`.
**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 |From Azure/documentdb-agent-kit, MIT.
More from Azure/documentdb-agent-kit
- 0.670score
documentdb-query-optimizer
AzureOfficial
Help with DocumentDB/MongoDB query optimization and indexing for Azure DocumentDB.
SkillBFreshness: B★ 6Claude Code +9 - 0.660score
documentdb-data-modeling
AzureOfficial
Data modeling patterns for Azure DocumentDB — embed vs reference, 16 MB document limit, denormalization for read-heavy workloads, schema versioning.
SkillBFreshness: B★ 6Claude Code +9 - 0.608score
documentdb-azure-deployment
AzureOfficial
Deploy an Azure DocumentDB cluster (`Microsoft.DocumentDB/mongoClusters`) end-to-end — Bicep (primary), Azure CLI one-shot, Terraform, or portal.
SkillCFreshness: C★ 6Claude Code +9 - 0.607score
documentdb-indexing
AzureOfficial
Index-type selection and shape guidance for Azure DocumentDB — when to use single-field, compound (ESR), multikey, wildcard, hashed, 2dsphere, TTL, and vector…
SkillCFreshness: C★ 6Claude Code +9 - 0.607score
documentdb-mcp-setup
AzureOfficial
Guide users through installing and configuring the DocumentDB MCP server for Azure DocumentDB.
SkillCFreshness: C★ 6Claude Code +9 - 0.607score
documentdb-vector-search
AzureOfficial
Vector search best practices for Azure DocumentDB using `cosmosSearch` — choosing between DiskANN / HNSW / IVF, creating indexes, tuning `lBuild` / `lSearch`…
SkillCFreshness: C★ 6Claude Code +9 - 0.607score
documentdb-full-text-search
AzureOfficial
Full-text search best practices for Azure DocumentDB using the `createSearchIndexes` command and `$search` aggregation stage — BM25 keyword scoring, fuzzy…
SkillCFreshness: C★ 6Claude Code +9 - 0.607score
documentdb-high-availability
AzureOfficial
High availability, business-continuity, and disaster-recovery best practices for Azure DocumentDB — enabling in-region HA with availability zones (99.99%…
SkillCFreshness: C★ 6Claude Code +9 - 0.607score
documentdb-natural-language-querying
AzureOfficial
Generate read-only DocumentDB/MongoDB queries (find) or aggregation pipelines using natural language, with collection schema context and sample documents.
SkillCFreshness: C★ 6Claude Code +9 - 0.607score
documentdb-sharding
AzureOfficial
Horizontal sharding (partitioning) for Azure DocumentDB collections — when to shard vs stay single-shard, how to pick a shard key for read-heavy vs…
SkillCFreshness: C★ 6Claude Code +9 - 0.607score
documentdb-storage
AzureOfficial
Storage configuration guidance for Azure DocumentDB — when and how to use Premium SSD v2 high-performance storage, IOPS/bandwidth caps that are gated by…
SkillCFreshness: C★ 6Claude Code +9 - 0.601score
documentdb-local-deployment
AzureOfficial
Best practices for running Azure DocumentDB locally for development — choosing between the Gateway Docker image and the psql-only image, docker-compose setup…
SkillCFreshness: C★ 6Claude Code +9
Compare and alternatives
Featured in
Signals
- Stars
- 6
- Forks
- 12
- Open issues
- 5
- Last commit (this folder)
- May 26, 2026 (5 months ago)
From GitHub (fetched Oct 24, 2026).
Details
- License
- MIT
- Repository
- github.com/Azure/documentdb-agent-kit
- 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 Azure
- 0.670score
documentdb-query-optimizer
AzureOfficial
Help with DocumentDB/MongoDB query optimization and indexing for Azure DocumentDB.
SkillBFreshness: B★ 6Claude Code +9 - 0.660score
documentdb-data-modeling
AzureOfficial
Data modeling patterns for Azure DocumentDB — embed vs reference, 16 MB document limit, denormalization for read-heavy workloads, schema versioning.
SkillBFreshness: B★ 6Claude Code +9 - 0.608score
documentdb-azure-deployment
AzureOfficial
Deploy an Azure DocumentDB cluster (`Microsoft.DocumentDB/mongoClusters`) end-to-end — Bicep (primary), Azure CLI one-shot, Terraform, or portal.
SkillCFreshness: C★ 6Claude Code +9 - 0.607score
documentdb-high-availability
AzureOfficial
High availability, business-continuity, and disaster-recovery best practices for Azure DocumentDB — enabling in-region HA with availability zones (99.99%…
SkillCFreshness: C★ 6Claude Code +9 - 0.607score
documentdb-full-text-search
AzureOfficial
Full-text search best practices for Azure DocumentDB using the `createSearchIndexes` command and `$search` aggregation stage — BM25 keyword scoring, fuzzy…
SkillCFreshness: C★ 6Claude Code +9 - 0.607score
documentdb-indexing
AzureOfficial
Index-type selection and shape guidance for Azure DocumentDB — when to use single-field, compound (ESR), multikey, wildcard, hashed, 2dsphere, TTL, and vector…
SkillCFreshness: C★ 6Claude Code +9
Cite this page
documentdb-connection skill. Agent Mart. https://agentmart.dev/skills/azure-documentdb-connection (last updated 2026-10-24)