mongo

package
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 19, 2025 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Client *mongo.Client
	// contains filtered or unexported fields
}

Client wraps mongo.Client and provides additional functionality

func Connect

func Connect(cfg MongoConfig) (*Client, error)

func (*Client) Collection

func (c *Client) Collection(name string) *mongo.Collection

Collection returns a handle to a collection in the configured database

func (*Client) Database

func (c *Client) Database() *mongo.Database

Database returns a handle to the configured database

func (*Client) Disconnect

func (c *Client) Disconnect(ctx context.Context) error

Disconnect closes the MongoDB connection

func (*Client) IsHealthy

func (c *Client) IsHealthy(ctx context.Context) bool

IsHealthy checks if the MongoDB connection is healthy

func (*Client) Ping

func (c *Client) Ping(ctx context.Context) error

Ping tests the MongoDB connection

func (*Client) WithTransaction

func (c *Client) WithTransaction(ctx context.Context, fn func(mongo.SessionContext) error) error

WithTransaction executes a function within a MongoDB transaction

type MongoConfig

type MongoConfig struct {
	URI            string
	DBName         string
	Timeout        time.Duration
	MaxPoolSize    uint64
	MinPoolSize    uint64
	MaxIdleTime    time.Duration
	MaxConnecting  uint64
	ReadPreference string // primary, secondary, primaryPreferred, secondaryPreferred, nearest
	RetryWrites    bool
	RetryReads     bool
}

Jump to

Keyboard shortcuts

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