mongo

package module
v2.8.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 2, 2021 License: MIT Imports: 5 Imported by: 0

README

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

Using mongo checker function currently pings a mongo client, further work to check mongo queries based on an applications requirements (level of access and to which databases and collections).

Read the Health Check Specification for details.

Instantiate a mongo health checker

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

...

    mongoClient := mongoHealth.NewClient(<mgo session>)

    mongoHealth := mongoHealth.CheckClient{
        client: mongoClient,
        healthcheck: mongoHealth.Healthcheck,
    }
...

Call mongo health checker with mongoHealth.Checker(context.Background()) and this will return a 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 .Create() function

Contributing

See CONTRIBUTING for details.

License

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

Released under MIT license, see LICENSE for details.

Documentation

Index

Constants

View Source
const (
	LastUpdatedKey     = "last_updated"
	UniqueTimestampKey = "unique_timestamp"
)

keep these in sync with Timestamps tags below

Variables

This section is empty.

Functions

func Close

func Close(ctx context.Context, session *mgo.Session) error

Close represents mongo session closing within the context deadline

func WithLastUpdatedUpdate

func WithLastUpdatedUpdate(updateDoc bson.M) (bson.M, error)

WithLastUpdatedUpdate adds last_updated to updateDoc

func WithNamespacedLastUpdatedUpdate

func WithNamespacedLastUpdatedUpdate(updateDoc bson.M, prefixes []string) (newUpdateDoc bson.M, err error)

WithNamespacedLastUpdatedUpdate adds unique timestamp to updateDoc

func WithNamespacedUniqueTimestampQuery

func WithNamespacedUniqueTimestampQuery(queryDoc bson.M, timestamps []bson.MongoTimestamp, prefixes []string) bson.M

WithNamespacedUniqueTimestampQuery adds unique timestamps to queryDoc sub-docs

func WithNamespacedUniqueTimestampUpdate

func WithNamespacedUniqueTimestampUpdate(updateDoc bson.M, prefixes []string) (newUpdateDoc bson.M, err error)

WithNamespacedUniqueTimestampUpdate adds unique timestamp to updateDoc

func WithNamespacedUpdates

func WithNamespacedUpdates(updateDoc bson.M, prefixes []string) (bson.M, error)

WithNamespacedUpdates adds all timestamps to updateDoc

func WithUniqueTimestampQuery

func WithUniqueTimestampQuery(queryDoc bson.M, timestamp bson.MongoTimestamp) bson.M

WithUniqueTimestampQuery adds unique timestamp to queryDoc

func WithUniqueTimestampUpdate

func WithUniqueTimestampUpdate(updateDoc bson.M) (bson.M, error)

WithUniqueTimestampUpdate adds unique timestamp to updateDoc

func WithUpdates

func WithUpdates(updateDoc bson.M) (bson.M, error)

WithUpdates adds all timestamps to updateDoc

Types

type Graceful

type Graceful interface {
	// contains filtered or unexported methods
}

Graceful represents an interface to the shutdown method

type Timestamps

type Timestamps struct {
	LastUpdated     time.Time            `bson:"last_updated,omitempty"     json:"last_updated,omitempty"`
	UniqueTimestamp *bson.MongoTimestamp `bson:"unique_timestamp,omitempty" json:"-"`
}

Timestamps represent an object containing time stamps keep these in sync with above const

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL