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 provide MongoClient instance.
  • databaseNameFactory: A factory method to provide database name.
  • name: The health check name. The default is mongodb.
  • failureStatus: The HealthStatus that should be reported when the health check fails. Default is HealthStatus.Unhealthy.
  • tags: A list of tags that can be used to filter sets of health checks.
  • timeout: A System.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.

Showing the top 20 packages that depend on AspNetCore.HealthChecks.MongoDb.

Packages Downloads
SanedBuildingBlocks
This package built for OIG-Saned
234
SanedBuildingBlocks
This package built for OIG-Saned
231
SanedBuildingBlocks
This package built for OIG-Saned
107
SanedBuildingBlocks
This package built for OIG-Saned
69
SanedBuildingBlocks
This package built for OIG-Saned
59
SanedBuildingBlocks
This package built for OIG-Saned
54
SanedBuildingBlocks
This package built for OIG-Saned
52
SanedBuildingBlocks
This package built for OIG-Saned
44
SanedBuildingBlocks
This package built for OIG-Saned
34
SanedBuildingBlocks
This package built for OIG-Saned
31
SanedBuildingBlocks
This package built for OIG-Saned
30
SanedBuildingBlocks
This package built for OIG-Saned
24
SanedBuildingBlocks
This package built for OIG-Saned
23
SanedBuildingBlocks
This package built for OIG-Saned
15
SanedBuildingBlocks
This package built for OIG-Saned
14
SanedBuildingBlocks
This package built for OIG-Saned
13

Version Downloads Last updated
9.0.0 22 03/06/2025
8.1.0 24 10/02/2024
8.0.1 30 03/06/2025
8.0.0 33 03/06/2025
7.0.0 33 11/29/2023
7.0.0-rc2.6 30 03/06/2025
7.0.0-rc2.5 32 03/06/2025
7.0.0-rc2.4 31 03/06/2025
7.0.0-rc2.3 31 03/06/2025
6.0.2 22 06/26/2023
6.0.1 19 03/06/2025
6.0.1-rc2.2 19 03/06/2025
6.0.1-rc1.1 22 02/18/2025
6.0.0 19 03/06/2025
5.0.1 19 03/06/2025
5.0.0 20 03/06/2025
5.0.0-preview1 20 02/18/2025
3.1.3 20 03/06/2025
3.1.2 21 03/06/2025
3.1.1 21 03/06/2025
3.1.0 20 03/06/2025
3.0.1 19 03/06/2025
3.0.0 21 03/06/2025
2.2.3 19 03/06/2025
2.2.2 21 03/06/2025
2.2.1 20 03/06/2025
2.2.0 21 03/06/2025