<!-- llms-explorer concept facts · https://llms-explorer.com/tree/pinned-aspire-mongodb-client-configuration-and-observability-registration-boundaries/ · pack 2026-11-02 · ~3374 tokens -->

# Pinned Aspire MongoDB client configuration and observability registration boundaries

> Source-anchored research for Pinned Aspire MongoDB client configuration and observability registration boundaries. Run status: COMPLETED.

Parent: [MongoDB Drivers](https://llms-explorer.com/tree/mongodb-drivers/) · 4 facets · 18 facts · page: https://llms-explorer.com/tree/pinned-aspire-mongodb-client-configuration-and-observability-registration-boundaries/

## Structure and components

- The pinned AddMongoDatabase returns without registering IMongoDatabase when the connection string is blank or its parsed MongoUrl has no database name. Otherwise it registers a singleton database resolved from the matching unkeyed or keyed IMongoClient. The pinned fixture contains assertions for database presence and absence for both registration methods, including authenticated URIs. (medium confidence) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/tests/Aspire.MongoDB.Driver.Tests/AspireMongoDBDriverExtensionsTests.cs)
- The complete connection guide explicitly says that this MongoDB client integration does not expose OpenTelemetry metrics. The complete pinned wrapper registers the tracing source and configures client logging but contains no metrics registration. These source statements do not turn logging or tracing setup into a MongoDB metric-emission guarantee. (low confidence) (verified as of 2026-11-02) — [source](https://aspire.dev/integrations/databases/mongodb/mongodb-connect/) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs)
- The complete connection guide describes default MongoDB health checks as verifying connectivity and commands and integrating with /health. The pinned contributor guidance places MapHealthChecks outside a client integration, while the MongoDB wrapper registers AddMongoDb through TryAddHealthCheck. Preserve these scopes: the pinned wrapper path contains no HTTP endpoint-mapping call, and those registrations do not supply evidence that a deployed endpoint is ready. (medium confidence) (verified as of 2026-11-02) — [source](https://aspire.dev/integrations/databases/mongodb/mongodb-connect/) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/README.md) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs)

## How it works

- The pinned TryGetConnectionString checks the exact ConnectionStrings:{connectionName} key first. Any non-null value counts as found, including an empty string. Only when that value is null and the encoded portable key differs does it try ConnectionStrings:{portableConnectionName}. GetMongoDBSettings uses a found value to replace ConnectionString before invoking configureSettings. (medium confidence) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Common/ConnectionStringConfigurationExtensions.cs)
- The shared registration path rejects a null builder and a null or empty connection name. The captured client factory calls ValidateSettings before MongoClientSettings.FromConnectionString. ValidateSettings calls ValidateConnectionString without overriding isEfDesignTime, whose declared default is false. That helper throws InvalidOperationException for a blank connection string when isEfDesignTime is false, and its message identifies ConnectionStrings and configuration sections. AddMongoDatabase also calls MongoUrl.Create on a nonblank string during registration, so URI parsing occurs separately from the later client-factory validation. (medium confidence) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Common/ConnectionStringValidation.cs)
- When DisableTracing is false, the pinned registration path adds the MongoDB.Driver.Core.Extensions.DiagnosticSources activity source to OpenTelemetry tracing. CreateMongoClient also assigns a ClusterConfigurator that subscribes DiagnosticsActivityEventSubscriber. The configureClientSettings delegate runs after that assignment, so a caller can replace the ClusterConfigurator and change that subscription behavior. (low confidence) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs)
- After the caller delegate, client creation adds Aspire library identification. It derives a nullable assembly-version value, appends the Aspire name marker and that value to existing LibraryInfo fields, or creates Aspire LibraryInfo when absent. (low confidence) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs)
- The pinned AddHealthCheck passes a TimeSpan measured in milliseconds to AddMongoDb only when HealthCheckTimeout is positive; a null, zero or negative value passes null. This expression supplies the health-check registration timeout and does not assign MongoClientSettings connection or command timeout properties. (low confidence) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs) · [also](https://raw.githubusercontent.com/microsoft/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/MongoDBSettings.cs)

## Comparisons and alternatives

- The pinned README Usage example uses the emphasized label `_AppHost.cs_` for the file where it calls AddMongoDBClient. Its AppHost extensions example places builder.AddMongoDB in the AppHost and consumes AddMongoDBClient in MyService Program.cs. The complete connection guide describes consuming apps and calls AddMongoDBClient on their IHostApplicationBuilder. Preserve this documentation-location discrepancy instead of treating the README’s first placement as an unqualified hosting requirement. (medium confidence) (verified as of 2026-11-02) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/README.md) · [also](https://aspire.dev/integrations/databases/mongodb/mongodb-connect/)

## Facts and statements

- The pinned GetMongoDBSettings creates settings, binds Aspire:MongoDB:Driver, then binds its connectionName subsection. A successful TryGetConnectionString replaces the bound ConnectionString. The configureSettings delegate runs last. Both public registration methods use this same sequence, so named settings also apply to the unkeyed method. (medium confidence) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs) · [also](https://aspire.dev/integrations/databases/mongodb/mongodb-connect/) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Common/ConnectionStringConfigurationExtensions.cs)
- The pinned public unkeyed method passes a null service key; the keyed method uses its name for connection lookup and the service key. AddMongoClient registers an IMongoClient singleton factory through AddSingleton or AddKeyedSingleton accordingly. Each factory calls CreateMongoClient with the captured connection name, integration settings and configureClientSettings delegate. The fixture resolves both forms and asserts distinct database objects for different configured names. (medium confidence) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/tests/Aspire.MongoDB.Driver.Tests/AspireMongoDBDriverExtensionsTests.cs)
- Database registration parses the integration settings connection string before the client factory runs. The later caller client-settings delegate does not determine that registration decision or the database name captured by the database factory. (low confidence) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs)
- After configureClientSettings, the pinned client factory fills a null LoggingSettings with a new LoggingSettings using the DI ILoggerFactory lookup; caller-supplied logging settings survive this null-coalescing assignment. The factory later constructs MongoClient. The complete connection guide attributes automatic logging and tracing to the client integration and lists MongoDB logging categories and the MongoDB diagnostic activity source. (medium confidence) (verified as of 2026-11-02) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs) · [also](https://aspire.dev/integrations/databases/mongodb/mongodb-connect/)
- Health registration skips disabled checks and blank connection strings. Its name is MongoDB.Driver for the unkeyed client and MongoDB.Driver_{connectionName} for a keyed client. It supplies the matching DI client and a database-name factory derived from the integration connection string to the MongoDB health-check registration. (medium confidence) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/tests/Aspire.MongoDB.Driver.Tests/AspireMongoDBDriverExtensionsTests.cs)
- TryAddHealthCheck forms its builder.Properties key by prefixing the supplied health-check name with Aspire, a dot, HealthChecks and another dot. It sets that key and invokes the registration action only if the key is absent. This guard deduplicates health-check registration; AddMongoClient still calls the singleton registration methods. (medium confidence) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Common/HealthChecksExtensions.cs)
- The pinned enabled-health fixtures set HealthCheckTimeout to 1, call CheckHealthAsync and assert that the expected named entry exists. The disabled-health fixtures assert that HealthCheckService is absent from their isolated host. The enabled fixtures do not assert a Healthy status or a measured timeout duration. (low confidence) — [source](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/tests/Aspire.MongoDB.Driver.Tests/AspireMongoDBDriverExtensionsTests.cs)
- The complete connection guide says Aspire.MongoDB.Driver targets MongoDB.Driver 2.x and Aspire.MongoDB.Driver.v3 targets 3.x, cites a binary breaking change in driver 3.0.0 and describes a future package transition. Treat those statements as that guide snapshot’s package guidance. The pinned contributor guidance says client integrations are separate NuGet packages that can version independently; source inspection at a development commit does not establish the contents or behavior of a particular released Aspire.MongoDB.Driver.v3 package. (medium confidence) (verified as of 2026-11-02) — [source](https://aspire.dev/integrations/databases/mongodb/mongodb-connect/) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/README.md) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/README.md)
- The complete connection guide’s Atlas example supplies a mongodb+srv connection string in ConnectionStrings. The pinned wrapper creates a MongoClient and configures client tracing and logging. These cited paths describe application client integration, not an Atlas database-log OTLP receiver; the pinned contributor guidance also excludes defining telemetry exporters from a client integration’s scope. (medium confidence) (verified as of 2026-11-02) — [source](https://aspire.dev/integrations/databases/mongodb/mongodb-connect/) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/Aspire.MongoDB.Driver/AspireMongoDBDriverExtensions.cs) · [also](https://raw.githubusercontent.com/dotnet/aspire/0efbfcb095bf85ccf89678193d64b46022e7657e/src/Components/README.md)
