Skip to content

Latest commit

 

History

History
76 lines (60 loc) · 2.14 KB

MongoDB.md

File metadata and controls

76 lines (60 loc) · 2.14 KB

LiteX HealthChecks MongoDB

MongoDB health checks package used to check the status of a MongoDB in ASP.NET Core applications.

LiteXHealthChecks is very small yet powerful and high-performance library used to check the status of a component in the application, such as a backend service, database or some internal state.

Basic Usage

Install the package

Install via Nuget.

PM> Install-Package LiteX.HealthChecks.MongoDB
AppSettings
{  
  "Data": {
    "ConnectionStrings": {
      "MongoDB": "--REPLACE WITH YOUR CONNECTION STRING--",
    }
  }
}
Configure Startup Class
public class Startup
{
    public IConfiguration Configuration { get; }

    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public void ConfigureServices(IServiceCollection services)
    {
        // 1: Use default configuration
        services.AddHealthChecks()
            .AddMongoDb(Configuration["Data:ConnectionStrings:MongoDB"]);

        // OR
        // 2: With all optional configuration
        services.AddHealthChecks()
            .AddMongoDb(
                connectionString: Configuration["Data:ConnectionStrings:MongoDB"],
                name: "mongodb",
                failureStatus: HealthStatus.Unhealthy,
                tags: new string[] { "db", "nosql", "mongodb" });

        // OR
        // 3: With all optional configuration
        services.AddHealthChecks()
            .AddMongoDb(
                connectionString: Configuration["Data:ConnectionStrings:MongoDB"],
                databaseName: "config",
                name: "mongodb",
                failureStatus: HealthStatus.Unhealthy,
                tags: new string[] { "db", "nosql", "mongodb" });
    }

    public void Configure(IApplicationBuilder app, IHostingEnvironment env)
    {
        app.UseHealthChecks("/health");
    }
}

Sample Usage Example

Sample for other services.

For more helpful information about LiteX HealthChecks, Please click here.