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
236
SanedBuildingBlocks
This package built for OIG-Saned
233
SanedBuildingBlocks
This package built for OIG-Saned
171
SanedBuildingBlocks
This package built for OIG-Saned
150
SanedBuildingBlocks
This package built for OIG-Saned
109
SanedBuildingBlocks
This package built for OIG-Saned
65
SanedBuildingBlocks
This package built for OIG-Saned
56
SanedBuildingBlocks
This package built for OIG-Saned
53
SanedBuildingBlocks
This package built for OIG-Saned
46
SanedBuildingBlocks
This package built for OIG-Saned
44
SanedBuildingBlocks
This package built for OIG-Saned
39
SanedBuildingBlocks
This package built for OIG-Saned
36
SanedBuildingBlocks
This package built for OIG-Saned
34
SanedBuildingBlocks
This package built for OIG-Saned
31
SanedBuildingBlocks
This package built for OIG-Saned
29
SanedBuildingBlocks
This package built for OIG-Saned
27
SanedBuildingBlocks
This package built for OIG-Saned
24
SanedBuildingBlocks
This package built for OIG-Saned
18

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