mongo

package
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Jan 29, 2025 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Client

func Client() (*mongo.Client, error)

Client returns the MongoDB client instance

func Close

func Close() error

Close closes the MongoDB client connection

func Collection

func Collection(dbName, collName string) (*mongo.Collection, error)

Collection returns a handle to the specified collection

func Database

func Database(name string) (*mongo.Database, error)

Database returns a handle to the specified database

func Health

func Health() error

Health checks if the MongoDB connection is healthy

func Init

func Init() (err error)

Init initializes the global MongoDB client. It reads MongoDB configuration from config.App.MongoConfig. If MongoDB is not enabled, it returns nil. The function is thread-safe and ensures the client is initialized only once.

func New added in v0.1.1

func New(cfg config.MongoConfig) (*mongo.Client, error)

New returns a new MongoDB client instance with given configuration. It's the caller's responsibility to close the client, caller should always call Close() when it's no longer needed.

Types

This section is empty.

Jump to

Keyboard shortcuts

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