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
359
SanedBuildingBlocks
This package built for OIG-Saned
240
SanedBuildingBlocks
This package built for OIG-Saned
237
SanedBuildingBlocks
This package built for OIG-Saned
233
SanedBuildingBlocks
This package built for OIG-Saned
202
SanedBuildingBlocks
This package built for OIG-Saned
112
SanedBuildingBlocks
This package built for OIG-Saned
103
SanedBuildingBlocks
This package built for OIG-Saned
69
SanedBuildingBlocks
This package built for OIG-Saned
61
SanedBuildingBlocks
This package built for OIG-Saned
59
SanedBuildingBlocks
This package built for OIG-Saned
57
SanedBuildingBlocks
This package built for OIG-Saned
53
SanedBuildingBlocks
This package built for OIG-Saned
49
SanedBuildingBlocks
This package built for OIG-Saned
46
SanedBuildingBlocks
This package built for OIG-Saned
45
SanedBuildingBlocks
KitSysCo Building Blocks
41
SanedBuildingBlocks
This package built for OIG-Saned
40
SanedBuildingBlocks
This package built for OIG-Saned
38
SanedBuildingBlocks
This package built for OIG-Saned
37
SanedBuildingBlocks
This package built for OIG-Saned
34

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