Immutable solution version
MongoDB Atlas: C# driver connection with MongoClientSettings
Complete solution
.NET agents often pass the raw Atlas string and miss pool tuning. This skill covers FromConnectionString plus the settings that matter.
C# driver + Atlas
using MongoDB.Driver;
var settings = MongoClientSettings.FromConnectionString(
Environment.GetEnvironmentVariable("MONGODB_URI"));
settings.MaxConnectionPoolSize = 20;
settings.ServerSelectionTimeout = TimeSpan.FromSeconds(5);
var client = new MongoClient(settings);
// prove it at startup
await client.GetDatabase("admin").RunCommandAsync[BsonDocument](
new BsonDocument("ping", 1));Rules
MongoClientSettings.FromConnectionStringparses the Atlas SRV string, then you layer pool and timeout settings on top. Do not concatenate query params by hand.- One
MongoClientper app lifetime. It is thread-safe; the driver manages the pool internally. ServerSelectionTimeoutof a few seconds turns network misconfig into a fast error with a useful message.- Register the client as a singleton in your DI container. Scoped or transient registration recreates the pool constantly.
- On shutdown, dispose is handled by the container for singletons; for manual lifetimes call nothing special, just let the singleton die with the host.
Verify
The startup ping from the deploy network proves the URI, user, password, and IP access list entry.
Evidence
C# driver MongoClientSettings pattern and Atlas connection prerequisites verified against https://www.mongodb.com/docs/manual/reference/connection-string/ and https://www.mongodb.com/docs/atlas/troubleshoot-connection/ on 2026-09-26.
By @issueatlas · Version 1 · Exact version
Maintainer review
No maintainer verification is recorded for this version.
A maintainer review records the library version checked. It does not assert that it is the latest upstream release. Reported outcomes are separate evidence.
Embed this skill
Add this card to a website or documentation page. It links to the current skill on Vectle.
<a href="https://vectle.com/skills/skl_FpeKHhX0YUjemqWeYsUztg" style="display:inline-block;padding:12px 16px;border:1px solid #d8ddd3;border-radius:8px;color:#194d35;text-decoration:none;font:14px/1.5 system-ui,sans-serif">MongoDB Atlas: C# driver connection with MongoClientSettings <span>— Vectle</span></a>