mongo

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 20, 2026 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (

	// DefaultConnectionTimeout specifies the default timeout duration in seconds.
	DefaultConnectionTimeout time.Duration = 10 * time.Second

	// DefaultConnectionPoolSize defines the default size for the connection pool
	DefaultConnectionPoolSize uint64 = 100
)

Variables

This section is empty.

Functions

func SetConnectionConfig

func SetConnectionConfig(clusterName string, config *ConnectionConfig)

func SetConnectionConfigE

func SetConnectionConfigE(clusterName string, config *ConnectionConfig) error

Types

type Client

type Client interface {
	Database(string, ...options.Lister[options.DatabaseOptions]) Database
	Disconnect(context.Context) error
	StartSession() (*mongo.Session, error)
	UseSession(ctx context.Context, fn func(context.Context) error) error
	Ping(context.Context) error
}

func Connect

func Connect(connector MongoConnector, clusterName string) (Client, error)

func ConnectContext

func ConnectContext(ctx context.Context, connector MongoConnector, clusterName string) (Client, error)

type Collection

type Collection interface {
	FindOne(context.Context, interface{}, ...options.Lister[options.FindOneOptions]) SingleResult
	InsertOne(context.Context, interface{}, ...options.Lister[options.InsertOneOptions]) (interface{}, error)
	InsertMany(context.Context, []interface{}, ...options.Lister[options.InsertManyOptions]) ([]interface{}, error)
	DeleteOne(context.Context, interface{}, ...options.Lister[options.DeleteOneOptions]) (int64, error)
	DeleteMany(context.Context, interface{}, ...options.Lister[options.DeleteManyOptions]) (int64, error)
	Find(context.Context, interface{}, ...options.Lister[options.FindOptions]) (Cursor, error)
	CountDocuments(context.Context, interface{}, ...options.Lister[options.CountOptions]) (int64, error)
	Aggregate(context.Context, interface{}, ...options.Lister[options.AggregateOptions]) (Cursor, error)
	UpdateOne(context.Context, interface{}, interface{}, ...options.Lister[options.UpdateOneOptions]) (*mongo.UpdateResult, error)
	UpdateMany(context.Context, interface{}, interface{}, ...options.Lister[options.UpdateManyOptions]) (*mongo.UpdateResult, error)
	FindOneAndUpdate(context.Context, interface{}, interface{}, ...options.Lister[options.FindOneAndUpdateOptions]) SingleResult
	BulkWrite(context.Context, []mongo.WriteModel, ...options.Lister[options.BulkWriteOptions]) (*mongo.BulkWriteResult, error)
}

type ConnectionConfig

type ConnectionConfig struct {
	Hosts              []string
	Username           string
	Password           string
	ConnectionTimeout  time.Duration
	ConnectionPoolsize int64
}

func (*ConnectionConfig) Validate

func (c *ConnectionConfig) Validate() error

type Cursor

type Cursor interface {
	Close(context.Context) error
	Next(context.Context) bool
	Decode(interface{}) error
	All(context.Context, interface{}) error
	Err() error
}

type Database

type Database interface {
	Collection(string, ...options.Lister[options.CollectionOptions]) Collection
}

type MongoConnector

type MongoConnector interface {
	Connect(context.Context, *options.ClientOptions) (Client, error)
}

type MongoDbConnector

type MongoDbConnector struct {
	DB Client
}

MongoDbConnector provides a struct implementation for the MongoDbConnectorInterface. It contains a DB field which represents the active MongoDB connection.

func (*MongoDbConnector) Connect

func (mdc *MongoDbConnector) Connect(ctx context.Context, clientOpts *options.ClientOptions) (Client, error)

type SingleResult

type SingleResult interface {
	Decode(interface{}) error
}

Jump to

Keyboard shortcuts

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