mongodb

package
v0.5.10 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: GPL-3.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	FailedToConnectError                = errors.New("failed to connect to MongoDB")
	AlreadyConnectedError               = errors.New("connection to MongoDB already established")
	NotConnectedError                   = errors.New("connection to MongoDB not established")
	FailedToDisconnectError             = errors.New("failed to disconnect from MongoDB")
	FailedToCreateDocumentError         = errors.New("failed to create document")
	FailedToStartSessionError           = errors.New("failed to start session")
	FailedToPingError                   = errors.New("failed to ping MongoDB")
	FailedToCreateSingleFieldIndexError = errors.New("failed to create single field index")
	FailedToCreateCompoundIndexError    = errors.New("failed to create compound index")
)

Functions

func LoadMongoDBName

func LoadMongoDBName(key string) (database string, err error)

LoadMongoDBName load MongoDB model name from environment variables

func LoadMongoDBURI

func LoadMongoDBURI(key string) (uri string, err error)

LoadMongoDBURI load MongoDB URI from environment variables

Types

type Collection

type Collection struct {
	Name               string
	SingleFieldIndexes *[]*SingleFieldIndex
	CompoundIndexes    *[]*CompoundFieldIndex
}

Collection represents a MongoDB collection

func NewCollection

func NewCollection(
	name string, singleFieldIndexes *[]*SingleFieldIndex,
	compoundIndexes *[]*CompoundFieldIndex,
) *Collection

NewCollection creates a new MongoDB collection

func (*Collection) CreateCollection

func (c *Collection) CreateCollection(database *mongo.Database) (
	collection *mongo.Collection, err error,
)

CreateCollection creates the collection

type CompoundFieldIndex

type CompoundFieldIndex struct {
	Model *mongo.IndexModel
}

CompoundFieldIndex represents a compound field index

func NewCompoundFieldIndex

func NewCompoundFieldIndex(
	fieldIndexes []*FieldIndex, unique bool,
) *CompoundFieldIndex

NewCompoundFieldIndex creates a new compound field index

type Config

type Config struct {
	Uri     string
	Timeout time.Duration
}

Config struct

type ConnectionHandler

type ConnectionHandler interface {
	Connect() (*mongo.Client, error)
	GetClient() (*mongo.Client, error)
	Disconnect()
}

ConnectionHandler interface

type DefaultConnectionHandler

type DefaultConnectionHandler struct {
	Ctx           context.Context
	Cancel        context.CancelFunc
	ClientOptions *options.ClientOptions
	Client        *mongo.Client
}

DefaultConnectionHandler struct

func NewDefaultConnectionHandler

func NewDefaultConnectionHandler(config *Config) DefaultConnectionHandler

NewDefaultConnectionHandler creates a new connection

func (DefaultConnectionHandler) Connect

func (d DefaultConnectionHandler) Connect() (*mongo.Client, error)

Connect returns a new MongoDB client

func (DefaultConnectionHandler) Disconnect

func (d DefaultConnectionHandler) Disconnect()

Disconnect closes the MongoDB client connection

func (DefaultConnectionHandler) GetClient

func (d DefaultConnectionHandler) GetClient() (*mongo.Client, error)

GetClient returns the MongoDB client

type FieldIndex

type FieldIndex struct {
	Name  string
	Order Order
}

func NewFieldIndex

func NewFieldIndex(name string, order Order) *FieldIndex

NewFieldIndex creates a new field index

type Logger

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

Logger is the logger for the MongoDB model

func NewLogger

func NewLogger(logger commonlogger.Logger) Logger

NewLogger is the logger for the MongoDB model

func (Logger) ConnectedToMongoDB

func (l Logger) ConnectedToMongoDB()

ConnectedToMongoDB logs a success message when the server connects from MongoDB

func (Logger) DisconnectedFromMongoDB

func (l Logger) DisconnectedFromMongoDB()

DisconnectedFromMongoDB logs a success message when the server disconnects from MongoDB

type Order

type Order int

Order represents the order of the index

const (
	// Ascending order
	Ascending Order = 1

	// Descending order
	Descending Order = -1
)

func (Order) OrderInt

func (o Order) OrderInt() int

OrderInt converts the Order type to an integer

type SingleFieldIndex

type SingleFieldIndex struct {
	Model *mongo.IndexModel
}

func NewSingleFieldIndex

func NewSingleFieldIndex(fieldIndex FieldIndex, unique bool) *SingleFieldIndex

NewSingleFieldIndex creates a new single field index

Directories

Path Synopsis
model

Jump to

Keyboard shortcuts

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