mongodb

package
v1.1.67 Latest Latest
Warning

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

Go to latest
Published: Feb 25, 2024 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewMongoDBConn

func NewMongoDBConn(ctx context.Context, cfg *common_utils.BaseConfig) (*mongo.Client, error)

Types

type MongoDB

type MongoDB interface {
	InsertOne(ctx context.Context, collection string, document any) (*mongo.InsertOneResult, error)
	InsertMany(ctx context.Context, collection string, documents []any) (*mongo.InsertManyResult, error)
	FindOne(ctx context.Context, collection string, filter any, opts ...*options.FindOneOptions) *mongo.SingleResult
	Find(ctx context.Context, collection string, filter any, opts ...*options.FindOptions) (*mongo.Cursor, error)
	FindOneAndUpdate(ctx context.Context, collection string, filter any, update any, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult
	FindOneAndReplace(ctx context.Context, collection string, filter any, replacement any, opts ...*options.FindOneAndReplaceOptions) *mongo.SingleResult
	FindOneAndDelete(ctx context.Context, collection string, filter any, opts ...*options.FindOneAndDeleteOptions) *mongo.SingleResult
	UpdateOne(ctx context.Context, collection string, filter any, update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	UpdateMany(ctx context.Context, collection string, filter any, update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
	DeleteOne(ctx context.Context, collection string, filter any, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
	DeleteMany(ctx context.Context, collection string, filter any, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)
	Aggregate(ctx context.Context, collection string, pipeline any, opts ...*options.AggregateOptions) (*mongo.Cursor, error)
	CountDocuments(ctx context.Context, collection string, filter any, opts ...*options.CountOptions) (int64, error)
	EstimatedDocumentCount(ctx context.Context, collection string, opts ...*options.EstimatedDocumentCountOptions) (int64, error)
	Distinct(ctx context.Context, collection string, fieldName string, filter any, opts ...*options.DistinctOptions) ([]any, error)
	Watch(ctx context.Context, collection string, pipeline any, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)
	Indexes(collection string) mongo.IndexView
	Collection(name string, opts ...*options.CollectionOptions) *mongo.Collection
	DropCollection(ctx context.Context, name string) error
	Client() *mongo.Client
	UseSession(ctx context.Context, fn func(mongo.SessionContext) error) error
	StartSession() (mongo.Session, error)
	CreateCollection(ctx context.Context, name string, opts ...*options.CreateCollectionOptions) error
}

func NewMongoDBClient

func NewMongoDBClient(client *mongo.Client, cfg *common_utils.BaseConfig) MongoDB

type MongoDBClient

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

func (*MongoDBClient) Aggregate

func (m *MongoDBClient) Aggregate(ctx context.Context, collection string, pipeline any, opts ...*options.AggregateOptions) (*mongo.Cursor, error)

func (*MongoDBClient) Client

func (m *MongoDBClient) Client() *mongo.Client

func (*MongoDBClient) Collection

func (m *MongoDBClient) Collection(name string, opts ...*options.CollectionOptions) *mongo.Collection

func (*MongoDBClient) CountDocuments

func (m *MongoDBClient) CountDocuments(ctx context.Context, collection string, filter any, opts ...*options.CountOptions) (int64, error)

func (*MongoDBClient) CreateCollection

func (m *MongoDBClient) CreateCollection(ctx context.Context, name string, opts ...*options.CreateCollectionOptions) error

func (*MongoDBClient) DeleteMany

func (m *MongoDBClient) DeleteMany(ctx context.Context, collection string, filter any, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*MongoDBClient) DeleteOne

func (m *MongoDBClient) DeleteOne(ctx context.Context, collection string, filter any, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func (*MongoDBClient) Distinct

func (m *MongoDBClient) Distinct(ctx context.Context, collection string, fieldName string, filter any, opts ...*options.DistinctOptions) ([]any, error)

func (*MongoDBClient) DropCollection

func (m *MongoDBClient) DropCollection(ctx context.Context, name string) error

func (*MongoDBClient) EstimatedDocumentCount

func (m *MongoDBClient) EstimatedDocumentCount(ctx context.Context, collection string, opts ...*options.EstimatedDocumentCountOptions) (int64, error)

func (*MongoDBClient) Find

func (m *MongoDBClient) Find(ctx context.Context, collection string, filter any, opts ...*options.FindOptions) (*mongo.Cursor, error)

func (*MongoDBClient) FindOne

func (m *MongoDBClient) FindOne(ctx context.Context, collection string, filter any, opts ...*options.FindOneOptions) *mongo.SingleResult

func (*MongoDBClient) FindOneAndDelete

func (m *MongoDBClient) FindOneAndDelete(ctx context.Context, collection string, filter any, opts ...*options.FindOneAndDeleteOptions) *mongo.SingleResult

func (*MongoDBClient) FindOneAndReplace

func (m *MongoDBClient) FindOneAndReplace(ctx context.Context, collection string, filter any, replacement any, opts ...*options.FindOneAndReplaceOptions) *mongo.SingleResult

func (*MongoDBClient) FindOneAndUpdate

func (m *MongoDBClient) FindOneAndUpdate(ctx context.Context, collection string, filter any, update any, opts ...*options.FindOneAndUpdateOptions) *mongo.SingleResult

func (*MongoDBClient) Indexes

func (m *MongoDBClient) Indexes(collection string) mongo.IndexView

func (*MongoDBClient) InsertMany

func (m *MongoDBClient) InsertMany(ctx context.Context, collection string, documents []any) (*mongo.InsertManyResult, error)

func (*MongoDBClient) InsertOne

func (m *MongoDBClient) InsertOne(ctx context.Context, collection string, document any) (*mongo.InsertOneResult, error)

func (*MongoDBClient) StartSession

func (m *MongoDBClient) StartSession() (mongo.Session, error)

func (*MongoDBClient) UpdateMany

func (m *MongoDBClient) UpdateMany(ctx context.Context, collection string, filter any, update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

func (*MongoDBClient) UpdateOne

func (m *MongoDBClient) UpdateOne(ctx context.Context, collection string, filter any, update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

func (*MongoDBClient) UseSession

func (m *MongoDBClient) UseSession(ctx context.Context, fn func(mongo.SessionContext) error) error

func (*MongoDBClient) Watch

func (m *MongoDBClient) Watch(ctx context.Context, collection string, pipeline any, opts ...*options.ChangeStreamOptions) (*mongo.ChangeStream, error)

Jump to

Keyboard shortcuts

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