mongodb

package
v0.3.6 Latest Latest
Warning

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

Go to latest
Published: Oct 30, 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")
View Source
var FailedToCreateCompoundIndexError = errors.New("failed to create compound index")
View Source
var FailedToCreateDocumentError = errors.New("failed to create document")
View Source
var FailedToCreateSingleFieldIndexError = errors.New("failed to create single field index")
View Source
var FailedToDisconnectError = errors.New("failed to disconnect from MongoDB")
View Source
var FailedToPingError = errors.New("failed to ping MongoDB")
View Source
var FailedToStartSessionError = errors.New("failed to start session")

Functions

func Disconnect added in v0.0.2

func Disconnect(connection *Connection)

Disconnect closes the MongoDB client connection

func LoadMongoDBName added in v0.3.0

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

LoadMongoDBName load MongoDB database name from environment variables

func LoadMongoDBURI added in v0.3.0

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

LoadMongoDBURI load MongoDB URI from environment variables

Types

type Collection added in v0.1.3

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

Collection represents a MongoDB collection

func NewCollection added in v0.1.3

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

NewCollection creates a new MongoDB collection

func (*Collection) CreateCollection added in v0.1.5

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

CreateCollection creates the collection

type CompoundFieldIndex added in v0.1.3

type CompoundFieldIndex struct {
	Model *mongo.IndexModel
}

CompoundFieldIndex represents a compound field index

func NewCompoundFieldIndex added in v0.1.3

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

NewCompoundFieldIndex creates a new compound field index

type Config added in v0.0.6

type Config struct {
	Uri     string
	Timeout time.Duration
}

type Connection added in v0.0.6

type Connection struct {
	Config *Config
	Client *mongo.Client
	Ctx    context.Context
	Cancel context.CancelFunc
}

func Connect

func Connect(config *Config) (connection *Connection, err error)

Connect returns a new MongoDB client

type FieldIndex added in v0.1.3

type FieldIndex struct {
	Name  string
	Order Order
}

func NewFieldIndex added in v0.1.3

func NewFieldIndex(name string, order Order) *FieldIndex

NewFieldIndex creates a new field index

type Logger added in v0.3.0

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

func NewLogger added in v0.3.0

func NewLogger(name string) *Logger

NewLogger is the logger for the MongoDB model

func (*Logger) ConnectedToMongoDB added in v0.3.0

func (m *Logger) ConnectedToMongoDB()

ConnectedToMongoDB logs a success message when the server connects from MongoDB

func (*Logger) DisconnectedFromMongoDB added in v0.3.0

func (m *Logger) DisconnectedFromMongoDB()

DisconnectedFromMongoDB logs a success message when the server disconnects from MongoDB

type Order added in v0.1.3

type Order int
const (
	// Ascending order
	Ascending Order = 1

	// Descending order
	Descending Order = -1
)

func (Order) OrderInt added in v0.1.3

func (o Order) OrderInt() int

OrderInt converts the Order type to an integer

type SingleFieldIndex added in v0.1.3

type SingleFieldIndex struct {
	Model *mongo.IndexModel
}

func NewSingleFieldIndex added in v0.1.3

func NewSingleFieldIndex(fieldIndex FieldIndex, unique bool) *SingleFieldIndex

NewSingleFieldIndex creates a new single field index

Directories

Path Synopsis
database

Jump to

Keyboard shortcuts

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