mongo

package
v0.0.6 Latest Latest
Warning

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

Go to latest
Published: Apr 18, 2026 License: MIT Imports: 6 Imported by: 0

README

mongo

Table of contents

Summary

Package mongo provides a mongo client factory and abstractions for interacting with mongo. It wraps the official mongo Go driver, exposing a simplified interface for connection management and database operations.

Architecture

Dependencies

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	// ErrPkg package error.
	ErrPkg = errors.New("mongodb")
	// ErrClient error.
	ErrClient = fmt.Errorf("%w: client error", ErrPkg)
)

Functions

func NewClient

func NewClient(config *Config) (*mongo.Client, error)

NewClient mongodb client factory.

Types

type Clienter

type Clienter interface {
	Connect(opts ...*options.ClientOptions) (*mongo.Client, error)
	Disconnect(ctx context.Context) error
	Ping(ctx context.Context, rp *readpref.ReadPref) error
	StartSession(opts ...options.Lister[options.SessionOptions]) (*mongo.Session, error)
	Database(name string, opts ...options.Lister[options.DatabaseOptions]) *mongo.Database
	ListDatabases(
		ctx context.Context,
		filter any,
		opts ...options.Lister[options.ListDatabasesOptions],
	) (mongo.ListDatabasesResult, error)
}

Clienter interface.

type Config

type Config struct {
	DSN      string `env:"DSN,default=mongodb://localhost:27017/database?retryWrites=false" json:"dsn"`
	Username string `env:"USERNAME,default=username"                                        json:"username"`
	Password string `env:"PASSWORD,default=password"                                        json:"password"`
}

Config database configuration loader.

Jump to

Keyboard shortcuts

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