mongo

package module
v1.3.2 Latest Latest
Warning

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

Go to latest
Published: Jul 7, 2023 License: MIT Imports: 12 Imported by: 1

README

Package mongo v1.3.2

Useful tools around MongoDB.

mongo.DefaultDatabaseName = "default-database"
mongo.Session(logger.Default())

Create a new session based on MONGO_URL, connection will be initialized only once, so you can call it everytime your need a session.

Will wait until database is available.

If no MONGO_URL is defined, will use mongodb://localhost:27017/ + DefaultDatabaseName

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	DefaultDatabaseName string
)

Functions

func BuildSession

func BuildSession(ctx context.Context, rawURL string) (*mgo.Session, error)

func Session

func Session(log logrus.FieldLogger) *mgo.Session

Session tries to open a session against a MongoDB database in a loop. The argument is NOT a context but a logger for the following reason. We create an initial connection and clone it. It means that only the initial session will have a context. Once this context expires the initial session is closed, and cloning it is not possible anymore, leading to errors in all cloned sessions. The linter `contextcheck` may complain that this function does not take a context in argument. In such case, add the following comment before the line calling this function: "//nolint: contextcheck"

Types

This section is empty.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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