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 provideMongoClient
instance.databaseNameFactory
: A factory method to provide database name.name
: The health check name. The default ismongodb
.failureStatus
: TheHealthStatus
that 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.TimeSpan
representing 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 | 1 | 01/18/2025 |
8.1.0 | 2 | 10/02/2024 |
8.0.1 | 3 | 10/01/2024 |
8.0.0 | 2 | 11/26/2024 |
7.0.0 | 2 | 11/26/2024 |
7.0.0-rc2.6 | 2 | 10/06/2024 |
7.0.0-rc2.5 | 2 | 11/26/2024 |
7.0.0-rc2.4 | 2 | 11/26/2024 |
7.0.0-rc2.3 | 2 | 10/02/2024 |
6.0.2 | 3 | 12/02/2022 |
6.0.1 | 3 | 10/04/2024 |
6.0.1-rc2.2 | 3 | 10/06/2024 |
6.0.1-rc1.1 | 2 | 10/04/2024 |
6.0.0 | 2 | 11/26/2024 |
5.0.1 | 157 | 12/09/2021 |
5.0.0 | 2 | 11/26/2024 |
5.0.0-preview1 | 1 | 11/26/2024 |
3.1.3 | 2 | 11/26/2024 |
3.1.2 | 3 | 10/06/2024 |
3.1.1 | 2 | 11/26/2024 |
3.1.0 | 2 | 11/26/2024 |
3.0.1 | 3 | 10/06/2024 |
3.0.0 | 2 | 11/26/2024 |
2.2.3 | 2 | 10/20/2024 |
2.2.2 | 2 | 11/26/2024 |
2.2.1 | 2 | 10/06/2024 |
2.2.0 | 3 | 10/06/2024 |