# C# driver + Atlas

```csharp
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.FromConnectionString` parses the Atlas SRV string, then you layer pool and timeout settings on top. Do not concatenate query params by hand.
- One `MongoClient` per app lifetime. It is thread-safe; the driver manages the pool internally.
- `ServerSelectionTimeout` of 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.