Skip to content

ONSdigital/dp-mongodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

254 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

dp-mongodb

A mongodb library for DP.

Getting started

Setting up mongo

Using brew, type brew install mongo or the latest binaries can be downloaded here

Running mongo

Follow instructions from mongo db manual

health package

The mongo checker function currently pings the mongo client, and checks that all collections given when the checker was created, actually exist.

Read the Health Check Specification for details.

Instantiate a mongo health checker

import mongoHealth "github.com/ONSdigital/dp-mongo/health"
import mongoDriver "github.com/ONSdigital/dp-mongo/mongodb"

...

    healthClient := mongoHealth.NewClientWithCollections(<mongoDriver.MongoConnection>, <map[mongoHealth.Database][]mongoHealth.Collection>)

...

Calling mongo health checker: healthClient.Checker(context.Context, *healthcheck.CheckState) will fill out the check object like so:

{
    "name": "string",
    "status": "string",
    "message": "string",
    "last_checked": "ISO8601 - UTC date time",
    "last_success": "ISO8601 - UTC date time",
    "last_failure": "ISO8601 - UTC date time"
}

Configuration

Configuration of the health check takes place via arguments passed to the NewClient() or NewClientWithCollections() functions

Tools

To run some of our tests you will need additional tooling:

Audit

We use dis-vulncheck to do auditing, which you will need to install.

Tests

The tests (both unit and component) for this library use testcontainers to run a mongodb Docker container. To run them you will need to have a Docker daemon running (e.g. colima).

Contributing

See CONTRIBUTING for details.

License

Copyright © 2024, Office for National Statistics (https://www.ons.gov.uk)

Released under MIT license, see LICENSE for details.

About

A mongo db library for Go.

Resources

License

Contributing

Stars

Watchers

Forks

Packages

No packages published

Contributors 16

Languages