mongoutil

package
v0.0.49 Latest Latest
Warning

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

Go to latest
Published: Aug 1, 2024 License: Apache-2.0 Imports: 11 Imported by: 4 modules, 16 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Aggregate

func Aggregate[T any](ctx context.Context, coll *mongo.Collection, pipeline any, opts ...*options.AggregateOptions) ([]T, error)

func Check

func Check(ctx context.Context, config *Config) error

CheckMongo tests the MongoDB connection without retries.

func Count

func Count(ctx context.Context, coll *mongo.Collection, filter any, opts ...*options.CountOptions) (int64, error)

func DecodeOne

func DecodeOne[T any](decoder func(v any) error) (res T, err error)

func Decodes

func Decodes[T any](ctx context.Context, cur *mongo.Cursor) ([]T, error)

func DeleteMany

func DeleteMany(ctx context.Context, coll *mongo.Collection, filter any, opts ...*options.DeleteOptions) error

func DeleteManyResult added in v0.0.49

func DeleteManyResult(ctx context.Context, coll *mongo.Collection, filter any, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func DeleteOne

func DeleteOne(ctx context.Context, coll *mongo.Collection, filter any, opts ...*options.DeleteOptions) error

func DeleteOneResult added in v0.0.49

func DeleteOneResult(ctx context.Context, coll *mongo.Collection, filter any, opts ...*options.DeleteOptions) (*mongo.DeleteResult, error)

func Exist

func Exist(ctx context.Context, coll *mongo.Collection, filter any, opts ...*options.CountOptions) (bool, error)

func Find

func Find[T any](ctx context.Context, coll *mongo.Collection, filter any, opts ...*options.FindOptions) ([]T, error)

func FindOne

func FindOne[T any](ctx context.Context, coll *mongo.Collection, filter any, opts ...*options.FindOneOptions) (res T, err error)

func FindOneAndUpdate

func FindOneAndUpdate[T any](ctx context.Context, coll *mongo.Collection, filter any, update any, opts ...*options.FindOneAndUpdateOptions) (res T, err error)

func FindPage

func FindPage[T any](ctx context.Context, coll *mongo.Collection, filter any, pagination pagination.Pagination, opts ...*options.FindOptions) (int64, []T, error)

func FindPageOnly

func FindPageOnly[T any](ctx context.Context, coll *mongo.Collection, filter any, pagination pagination.Pagination, opts ...*options.FindOptions) ([]T, error)

func Ignore added in v0.0.49

func Ignore[T any](_ T, err error) error

func IgnoreWarp added in v0.0.49

func IgnoreWarp[T any](_ T, err error) error

func IncrVersion added in v0.0.49

func IncrVersion(dbs ...func() error) error

func InsertMany

func InsertMany[T any](ctx context.Context, coll *mongo.Collection, val []T, opts ...*options.InsertManyOptions) error

func NewMongo

func NewMongo(client *mongo.Client) tx.Tx

func NewMongoTx

func NewMongoTx(ctx context.Context, client *mongo.Client) (tx.Tx, error)

func UpdateMany

func UpdateMany(ctx context.Context, coll *mongo.Collection, filter any, update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

func UpdateOne

func UpdateOne(ctx context.Context, coll *mongo.Collection, filter any, update any, notMatchedErr bool, opts ...*options.UpdateOptions) error

func UpdateOneResult

func UpdateOneResult(ctx context.Context, coll *mongo.Collection, filter any, update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)

Types

type Client

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

func NewMongoDB

func NewMongoDB(ctx context.Context, config *Config) (*Client, error)

NewMongoDB initializes a new MongoDB connection.

func (*Client) GetDB

func (c *Client) GetDB() *mongo.Database

func (*Client) GetTx

func (c *Client) GetTx() tx.Tx

type Config

type Config struct {
	Uri         string
	Address     []string
	Database    string
	Username    string
	Password    string
	MaxPoolSize int
	MaxRetry    int
}

Config represents the MongoDB configuration.

func (*Config) ValidateAndSetDefaults

func (c *Config) ValidateAndSetDefaults() error

ValidateAndSetDefaults validates the configuration and sets default values.

Jump to

Keyboard shortcuts

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