mongodb

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client added in v0.0.5

type Client struct {
	Mgos map[string]*mongo.Client
	// contains filtered or unexported fields
}

func NewClient added in v0.0.9

func NewClient(os ...Option) *Client

func (*Client) Close added in v0.0.5

func (c *Client) Close()

Close close all connection.

func (*Client) GetColl added in v0.0.5

func (c *Client) GetColl(dataBase, coll string) *mongo.Collection

func (*Client) GetCtx added in v0.0.5

func (c *Client) GetCtx(ctx context.Context) context.Context

func (*Client) Ping added in v0.0.5

func (c *Client) Ping() []error

Close ping all connection.

type ClientOptions added in v0.0.5

type ClientOptions struct{}

func (ClientOptions) WithConf added in v0.0.5

func (ClientOptions) WithConf(conf config.Config) Option

func (ClientOptions) WithDbConfig added in v0.0.5

func (ClientOptions) WithDbConfig(dbConfigs []MgoConfig) Option

func (ClientOptions) WithLogger added in v0.0.5

func (ClientOptions) WithLogger(logger log.Logger) Option

func (ClientOptions) WithMonitorEvent added in v0.0.5

func (ClientOptions) WithMonitorEvent(mongoEvent ...func() MgoEvent) Option

type EventOption

type EventOption func(c *MonitorEvent)

type MgoConfig

type MgoConfig struct {
	Db  string `json:"db" yaml:"db"`
	URI string `json:"uri" yaml:"uri"`
}

type MgoEvent added in v0.0.9

type MgoEvent interface {
	NextEvent(MgoEvent)

	EventName() string

	Start(context.Context, *event.CommandStartedEvent)

	SucceededEvent(context.Context, *event.CommandSucceededEvent)

	FailedEvent(context.Context, *event.CommandFailedEvent)
}

func NewMonitorEvent

func NewMonitorEvent(options ...EventOption) MgoEvent

type Mongo

type Mongo interface {
	Clone(opts ...*options.CollectionOptions) (*mongo.Collection, error)

	Name() string

	Database() *mongo.Database

	BulkWrite(ctx context.Context, models []mongo.WriteModel,
		opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, error)

	InsertOne(ctx context.Context, document interface{},
		opts ...*options.InsertOneOptions) (*mongo.InsertOneResult, error)

	InsertMany(ctx context.Context, documents []interface{},
		opts ...*options.InsertManyOptions) (*mongo.InsertManyResult, error)

	DeleteOne(ctx context.Context, filter interface{},
		opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

	DeleteMany(ctx context.Context, filter interface{},
		opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

	UpdateOne(ctx context.Context, filter interface{}, update interface{},
		opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

	UpdateMany(ctx context.Context, filter interface{}, update interface{},
		opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

	ReplaceOne(ctx context.Context, filter interface{},
		replacement interface{}, opts ...*options.ReplaceOptions) (*mongo.UpdateResult, error)

	Aggregate(ctx context.Context, pipeline interface{},
		opts ...*options.AggregateOptions) (*mongo.Cursor, error)

	CountDocuments(ctx context.Context, filter interface{},
		opts ...*options.CountOptions) (int64, error)

	EstimatedDocumentCount(ctx context.Context,
		opts ...*options.EstimatedDocumentCountOptions) (int64, error)

	Distinct(ctx context.Context, fieldName string, filter interface{},
		opts ...*options.DistinctOptions) ([]interface{}, error)

	Find(ctx context.Context, filter interface{},
		opts ...*options.FindOptions) (*mongo.Cursor, error)

	FindOne(ctx context.Context, filter interface{},
		opts ...*options.FindOneOptions) *mongo.SingleResult

	FindOneAndDelete(ctx context.Context, filter interface{},
		opts ...*options.FindOneAndDeleteOptions) *mongo.SingleResult

	FindOneAndReplace(ctx context.Context, filter interface{},
		replacement interface{}, opts ...*options.FindOneAndReplaceOptions) *mongo.SingleResult

	FindOneAndUpdate(ctx context.Context, filter interface{},
		update interface{}, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult

	Watch(ctx context.Context, pipeline interface{},
		opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)

	Indexes() mongo.IndexView

	Drop(ctx context.Context) error
}

type MonitorEvent

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

func (*MonitorEvent) EventName

func (m *MonitorEvent) EventName() string

func (*MonitorEvent) FailedEvent

func (m *MonitorEvent) FailedEvent(ctx context.Context, failedEvent *event.CommandFailedEvent)

func (*MonitorEvent) NextEvent

func (m *MonitorEvent) NextEvent(me MgoEvent)

func (*MonitorEvent) Start

func (m *MonitorEvent) Start(ctx context.Context, starEv *event.CommandStartedEvent)

func (*MonitorEvent) SucceededEvent

func (m *MonitorEvent) SucceededEvent(ctx context.Context,
	succEvent *event.CommandSucceededEvent)

type MonitorEventOptions

type MonitorEventOptions struct{}

func (MonitorEventOptions) WithConf

func (MonitorEventOptions) WithLogger

func (MonitorEventOptions) WithLogger(logger log.Logger) EventOption

func (MonitorEventOptions) WithTracer

type Option

type Option func(c *Client)

Jump to

Keyboard shortcuts

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