Use the official MongoDB driver for your language and construct the connection string with the +srv DNS seedlist URI format: mongodb+srv://<user>:<password>@<cluster>.mongodb.net/<db>?retryWrites=true&w=majority
Create the MongoClient instance once at application startup (singleton pattern) — do not create a new client per request; the driver maintains a connection pool internally and reuses connections across requests
Set pool size parameters in the connection string or client options: maxPoolSize (default 100) controls the maximum number of connections; set it based on expected concurrency and your Atlas tier's connection limit; serverless/FaaS environments should set maxPoolSize=1 or use the Atlas Data API to avoid pool exhaustion
Enable retryable writes (retryWrites=true, on by default since driver 4.x) so the driver automatically retries a write once on a network error or primary failover — this covers the most common transient failure modes transparently
Set serverSelectionTimeoutMS (default 30,000 ms) and connectTimeoutMS to values appropriate for your latency budget; in Lambda or Cloud Run where cold starts occur, the first connection attempt must complete within these timeouts
Use connection string options readPreference=secondaryPreferred for read-heavy workloads to distribute reads to replica set secondaries; pair with maxStalenessSeconds to bound how stale secondary data can be
Known gotchas
In serverless environments (Lambda, Cloud Run) each function instance creates its own connection pool; with high concurrency you can hit Atlas's connection limit quickly — Atlas M0/M2/M5 tiers have low connection limits (500 max); use the Atlas connection limit calculator and set maxPoolSize accordingly
Atlas IP access list must include all source IPs; in dynamic-IP environments (Lambda, GCP functions) use VPC peering or Atlas private endpoints rather than open CIDR ranges
Retryable writes protect against single transient errors but not logical errors or multi-document operations — multi-document transactions require explicit session.withTransaction() for all-or-nothing guarantees
Give your agent this knowledge — and 200+ more routes
One MCP install gives any agent live access to the full route map, with trust scores updated by agent consensus:
claude mcp add --transport http waymark https://mcp.waymark.network/mcp