🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Sign inDemoInstall
Socket

AspNetCore.HealthChecks.MongoDb

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

AspNetCore.HealthChecks.MongoDb

HealthChecks.MongoDb is the health check package for MongoDb.

9.0.0
NuGet
Version published
Maintainers
1
Created
Source

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.

Keywords

HealthCheck

FAQs

Package last updated on 19 Dec 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts