AspNetCore.HealthChecks.MongoDb 9.0.0
MongoDB Health Check
This health check verifies the ability to communicate with MongoDB. It uses the provided MongoClient to list database names or ping configured database.
Defaults
By default, the MongoClient instance is resolved from service provider.
void Configure(IHealthChecksBuilder builder)
{
builder.Services
.AddSingleton(sp => new MongoClient("mongodb://localhost:27017"))
.AddHealthChecks()
.AddMongoDb();
}
Customization
You can additionally add the following parameters:
clientFactory: A factory method to provideMongoClientinstance.databaseNameFactory: A factory method to provide database name.name: The health check name. The default ismongodb.failureStatus: TheHealthStatusthat should be reported when the health check fails. Default isHealthStatus.Unhealthy.tags: A list of tags that can be used to filter sets of health checks.timeout: ASystem.TimeSpanrepresenting the timeout of the check.
void Configure(IHealthChecksBuilder builder)
{
builder.Services
.AddSingleton(sp => new MongoClient("mongodb://localhost:27017"))
.AddHealthChecks()
.AddMongoDb(databaseNameFactory: sp => "theName");
}
Breaking changes
MongoDbHealthCheck was letting the users specify how MongoClient should be created (from raw connection string or from MongoUrl or from MongoClientSettings), at a cost of maintaining an internal, static client instances cache. Now the type does not create client instances nor maintain an internal cache and it's the caller responsibility to provide the instance of MongoClient (please see #2048 for more details). Since MongoDB recommends treating clients as singletons and client instances can be expensive to create, it's recommended to register a singleton factory method for MongoClient. So the client is created only when needed and once per whole application lifetime.
No packages depend on AspNetCore.HealthChecks.MongoDb.
.NET Framework 4.7.2
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.11)
- MongoDB.Driver (>= 3.0.0)
.NET 8.0
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.11)
- MongoDB.Driver (>= 3.0.0)
.NET Standard 2.1
- Microsoft.Extensions.Diagnostics.HealthChecks (>= 8.0.11)
- MongoDB.Driver (>= 3.0.0)
| Version | Downloads | Last updated |
|---|---|---|
| 9.0.0 | 23 | 01/18/2025 |
| 8.1.0 | 19 | 10/02/2024 |
| 8.0.1 | 25 | 10/01/2024 |
| 8.0.0 | 22 | 11/26/2024 |
| 7.0.0 | 21 | 11/26/2024 |
| 7.0.0-rc2.6 | 18 | 10/06/2024 |
| 7.0.0-rc2.5 | 23 | 11/26/2024 |
| 7.0.0-rc2.4 | 16 | 11/26/2024 |
| 7.0.0-rc2.3 | 23 | 10/02/2024 |
| 6.0.2 | 19 | 12/02/2022 |
| 6.0.1 | 21 | 10/04/2024 |
| 6.0.1-rc2.2 | 23 | 10/06/2024 |
| 6.0.1-rc1.1 | 18 | 10/04/2024 |
| 6.0.0 | 23 | 11/26/2024 |
| 5.0.1 | 173 | 12/09/2021 |
| 5.0.0 | 23 | 11/26/2024 |
| 5.0.0-preview1 | 23 | 11/26/2024 |
| 3.1.3 | 19 | 11/26/2024 |
| 3.1.2 | 23 | 10/06/2024 |
| 3.1.1 | 19 | 11/26/2024 |
| 3.1.0 | 22 | 11/26/2024 |
| 3.0.1 | 25 | 10/06/2024 |
| 3.0.0 | 23 | 11/26/2024 |
| 2.2.3 | 22 | 10/20/2024 |
| 2.2.2 | 21 | 11/26/2024 |
| 2.2.1 | 22 | 10/06/2024 |
| 2.2.0 | 22 | 10/06/2024 |