mongo

package
v1.3.1 Latest Latest
Warning

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

Go to latest
Published: Mar 19, 2024 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ReadPreferenceFromString

func ReadPreferenceFromString(src ConnectionReadPreference) *readpref.ReadPref

func StringifyBSON

func StringifyBSON(val interface{}) string

StringifyBSON converts arbitrary BSON to json-like string. it returns empty string on any error.

Types

type ConnectionConfig

type ConnectionConfig struct {
	// mongodb://user:password@host:port/dbname?options
	// https://www.mongodb.com/docs/manual/reference/connection-string/
	URI string `mapstructure:"uri"`

	// Query log config
	QueryLog *QueryLoggingConfig `mapstructure:"query_log"`
}

func (*ConnectionConfig) Validate

func (c *ConnectionConfig) Validate() error

type ConnectionReadPreference

type ConnectionReadPreference string
const (
	ReadPreferencePrimary            ConnectionReadPreference = "primary"
	ReadPreferencePrimaryPreferred   ConnectionReadPreference = "primary preferred"
	ReadPreferenceSecondaryPreferred ConnectionReadPreference = "secondary preferred"
	ReadPreferenceSecondary          ConnectionReadPreference = "secondary"
	ReadPreferenceNearest            ConnectionReadPreference = "nearest"
)

type ConnectionsConfig

type ConnectionsConfig map[string]*ConnectionConfig

func (*ConnectionsConfig) Validate

func (c *ConnectionsConfig) Validate() error

type Container

type Container struct {
	// contains filtered or unexported fields
}

Container is a simple container for holding named mongo connections. It's a helper for sharing same connection between several components.

func NewContainer

func NewContainer() *Container

func (*Container) Connect

func (cont *Container) Connect(appName string, name string, cfg *ConnectionConfig) error

Connect creates a new named mongo connection.

func (*Container) Get

func (cont *Container) Get(name string) *mongo.Client

Get gets a connection from the container

type QueryLoggingConfig

type QueryLoggingConfig struct {
	// Whether to log all queries
	All bool `mapstructure:"all"`

	// Whether to log slow queries
	Slow bool `mapstructure:"slow"`

	// Queries that were executed longer than that time will appear in slow log
	SlowThreshold time.Duration `mapstructure:"slow_threshold"`
}

func (*QueryLoggingConfig) Validate

func (c *QueryLoggingConfig) Validate() error

Jump to

Keyboard shortcuts

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