mongodb

package
v0.0.0-...-b797f85 Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2022 License: MIT Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrMsgDecode  = "failed to decode document due to error: %w"
	ErrMsgQuery   = "failed to execute query due to error: %w"
	ErrMsgFromHex = "failed to convert hex to primitive.ObjectID due to error: %w"
)

Variables

View Source
var ErrNormalizeFilter = errors.New("couldn't normalize filter")

Functions

This section is empty.

Types

type Collection

type Collection[T any] struct {
	Inner *mongo.Collection
	Log   *zap.Logger
}

func (*Collection[T]) All

func (*Collection[T]) All(ctx context.Context, cur *mongo.Cursor) (docs []T, err error)

func (*Collection[T]) CountDocuments

func (c *Collection[T]) CountDocuments(ctx context.Context, filter any, opts ...*options.CountOptions) (count uint64, err error)

func (*Collection[T]) Decode

func (*Collection[T]) Decode(r *mongo.SingleResult) (doc T, err error)

func (*Collection[T]) DeleteOne

func (c *Collection[T]) DeleteOne(ctx context.Context, filter any, opts ...*options.DeleteOptions) (err error)

func (*Collection[T]) Find

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

func (*Collection[T]) FindOne

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

func (*Collection[T]) FindOptions

func (*Collection[T]) FindOptions(index uint64, size uint32) *options.FindOptions

func (*Collection[T]) InsertOne

func (c *Collection[T]) InsertOne(ctx context.Context, document T, opts ...*options.InsertOneOptions) (string, error)

func (*Collection[T]) NormalizeFilter

func (c *Collection[T]) NormalizeFilter(filter any) (data any, err error)

func (*Collection[T]) ObjectID

func (*Collection[T]) ObjectID(id string) (primitive.ObjectID, error)

func (*Collection[T]) ToM

func (c *Collection[T]) ToM(doc T) (bson.M, error)

func (*Collection[T]) UpdateOne

func (c *Collection[T]) UpdateOne(ctx context.Context, filter any, update any, opts ...*options.UpdateOptions) (err error)

type Config

type Config struct {
	URI string `yaml:"uri" env:"URI" env-required:"true"`
}

func (*Config) GetClient

func (cfg *Config) GetClient(ctx context.Context) (*mongo.Client, error)

func (*Config) GetDatabase

func (cfg *Config) GetDatabase(ctx context.Context) (*mongo.Database, error)

Jump to

Keyboard shortcuts

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