connect

package
v1.8.1-0...-0157f87 Latest Latest
Warning

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

Go to latest
Published: Dec 12, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidConnection = errors.New("invalid mongo connection")

Functions

func Connect

func Connect(ctx context.Context, uri, appName string) (*clientImpl, error)

Connect resolves MongoDB connection to Primary member and wraps it within Client object. In case of replica set it returns connection to Primary member, while in case of sharded cluster it returns connection to Config RS Primary member.

func MongoConnect

func MongoConnect(
	ctx context.Context,
	uri string,
	mongoOptions ...MongoOption,
) (*mongo.Client, error)

func MongoConnectWithOpts

func MongoConnectWithOpts(ctx context.Context,
	uri string,
	mongoOptions ...MongoOption,
) (*mongo.Client, *options.ClientOptions, error)

func UnsafeClient

func UnsafeClient(m *mongo.Client) *clientImpl

Types

type Client

type Client interface {
	Disconnect(ctx context.Context) error

	MongoClient() *mongo.Client
	MongoOptions() *options.ClientOptions

	ConfigDatabase() *mongo.Database
	AdminCommand(ctx context.Context, cmd bson.D, opts ...*options.RunCmdOptions) *mongo.SingleResult

	LogCollection() *mongo.Collection
	ConfigCollection() *mongo.Collection
	LockCollection() *mongo.Collection
	LockOpCollection() *mongo.Collection
	BcpCollection() *mongo.Collection
	RestoresCollection() *mongo.Collection
	CmdStreamCollection() *mongo.Collection
	PITRChunksCollection() *mongo.Collection
	PITRCollection() *mongo.Collection
	PBMOpLogCollection() *mongo.Collection
	AgentsStatusCollection() *mongo.Collection
}

type MongoOption

type MongoOption func(*options.ClientOptions) error

func AppName

func AppName(name string) MongoOption

func ConnectTimeout

func ConnectTimeout(d time.Duration) MongoOption

func Direct

func Direct(direct bool) MongoOption

func NoRS

func NoRS() MongoOption

NoRS option removes replica set name setting

func ReadConcern

func ReadConcern(readConcern *readconcern.ReadConcern) MongoOption

ReadConcern option sets availability guarantees for read operation. For PBM typically use: readconcern.Local or readconcern.Majority. If the option is not specified the default is: readconcern.Majority.

func ServerSelectionTimeout

func ServerSelectionTimeout(d time.Duration) MongoOption

func WriteConcern

func WriteConcern(writeConcern *writeconcern.WriteConcern) MongoOption

WriteConcern option sets level of acknowledgment for write operation. For PBM typically use: writeconcern.W1 or writeconcern.Majority. If the option is not specified the default is: writeconcern.Majority.

Jump to

Keyboard shortcuts

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