mongo

package
v0.0.23 Latest Latest
Warning

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

Go to latest
Published: May 12, 2023 License: Apache-2.0 Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var NewSession = func(ctx context.Context, opt config.Mongo) (ISession, error) {
	serverAPIOptions := options.ServerAPI(options.ServerAPIVersion1)
	authentication := ""
	database := ""
	permission := "?retryWrites=true&w=majority"
	if opt.MongoUsername != "" && opt.MongoPassword != "" {
		authentication = fmt.Sprintf("%s:%s@", opt.MongoUsername, opt.MongoPassword)
	}
	if opt.MongoDatabase != "" {
		database = fmt.Sprintf("/%s", opt.MongoDatabase)
	}
	if opt.MongoAuthSource {
		permission = "?authSource=admin"
	}
	if opt.MongoIgnoreQueryString {
		permission = ""
	}

	clientOptions := options.Client().
		ApplyURI(fmt.Sprintf("%s://%s%s%s%s", opt.MongoProtocol, authentication, opt.MongoHost, database, permission)).
		SetServerAPIOptions(serverAPIOptions)
	return newClient(ctx, clientOptions)
}

NewSession method

Functions

This section is empty.

Types

type ISession

type ISession interface {
	Connect(ctx context.Context) error
	Disconnect(ctx context.Context) error
	Ping(ctx context.Context, rp *readpref.ReadPref) error
	StartSession(opts ...*options.SessionOptions) (mongo.Session, error)
	Database(name string, opts ...*options.DatabaseOptions) *mongo.Database
	ListDatabases(ctx context.Context, filter interface{}, opts ...*options.ListDatabasesOptions) (mongo.ListDatabasesResult, error)
	ListDatabaseNames(ctx context.Context, filter interface{}, opts ...*options.ListDatabasesOptions) ([]string, error)
	UseSession(ctx context.Context, fn func(mongo.SessionContext) error) error
	UseSessionWithOptions(ctx context.Context, opts *options.SessionOptions, fn func(mongo.SessionContext) error) error
	Watch(ctx context.Context, pipeline interface{},
		opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)
	NumberSessionsInProgress() int
	Timeout() *time.Duration
}

ISession interface

func NewExtendMongoDatabase added in v0.0.15

func NewExtendMongoDatabase(logger *zap.Logger, opt config.Mongo) (ISession, func(), error)

Jump to

Keyboard shortcuts

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