mongodb

package
v0.0.0-...-7bc4f86 Latest Latest
Warning

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

Go to latest
Published: Sep 8, 2023 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SortDescending = -1
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	URL      string
	Database string
}

type DB

type DB interface {
	GetCollection(collection string) *mongo.Collection
	FindById(ctx context.Context, collection string, id string, result interface{}) error
	FindOne(ctx context.Context, collection string, result interface{}, opts ...Option) error
	Find(ctx context.Context, collection string, result interface{}, opts ...Option) error
	UpdateMany(ctx context.Context, collection string, filter, update interface{}, options *options.UpdateOptions) error
	UpdateOne(ctx context.Context, collection string, filter, update interface{}, options *options.UpdateOptions) error
	UpdateOneRaw(ctx context.Context, collection string, filter, update interface{}, options *options.UpdateOptions) error
	UpdateManyRaw(ctx context.Context, collection string, filter, update interface{}, options *options.UpdateOptions) error
	Insert(ctx context.Context, collection string, document interface{}) error
	EnsureIndexes(ctx context.Context, collection string, model []mongo.IndexModel) error
	Delete(ctx context.Context, collection string, filter interface{}, opts *options.DeleteOptions) error
	WithTransaction(callback func(sc mongo.SessionContext) (interface{}, error)) (interface{}, error)
	FindOneAndUpdate(ctx context.Context, collection string, filter, update interface{}, opts *options.FindOneAndUpdateOptions, result interface{}) error
	Count(ctx context.Context, collection string, filter interface{}, opts ...*options.CountOptions) (int64, error)
	BulkWriteRaw(ctx context.Context, collection string, operations []mongo.WriteModel, opts ...*options.BulkWriteOptions) error
	Close()
}

func New

func New(config *Config) (DB, error)

type Option

type Option interface {
	// contains filtered or unexported methods
}

func WithFilter

func WithFilter(filter interface{}) Option

WithFilter - default not filter

Use bson object to filter document

see more: https://docs.mongodb.com/manual/reference/operator/query/

func WithHint

func WithHint(hint interface{}) Option

func WithPaging

func WithPaging(dPaging *paging.Pagination) Option

func WithSorter

func WithSorter(sorter interface{}) Option

WithSorter - default sort descending by `_id` field

{ $sort: { <field1>: <sort order>, <field2>: <sort order> ... }}

$sort takes a document that specifies the field(s) to sort by and the respective sort order. <sort order> can have one of the following values:

1 Sort ascending

-1 Sort descending

{ $meta: "textScore" } Sort by the computed textScore metadata in descending order

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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