mongodb

package module
v0.0.0-...-c7a7cc4 Latest Latest
Warning

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

Go to latest
Published: Jul 23, 2022 License: MIT Imports: 13 Imported by: 1

README

MongoDB

License

Installation

Use go get.

go get github.com/go-funcards/mongodb

Then import mongodb package into your own code.

import "github.com/go-funcards/mongodb"

License

Distributed under MIT License, please see license file within the code for more details.

Documentation

Index

Constants

View Source
const (
	ErrMsgDecode    = "failed to decode document due to error: %w"
	ErrMsgQuery     = "failed to execute query due to error: %w"
	ErrMsgMarshal   = "failed to marshal document due to error: %w"
	ErrMsgUnmarshal = "failed to unmarshal document due to error: %w"
)
View Source
const ErrMsgClient = "failed to create mongodb client"
View Source
const ErrMsgDatabase = "failed to create mongodb database"

Variables

View Source
var ErrNoDB = errors.New("database name not found in URI")

Functions

func All

func All(name string, value ...any) *field

func And

func And(expr ...Expr) *logical

func DecodeAll

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

func DecodeOne

func DecodeOne[T any](r *mongo.SingleResult) (doc T, err error)

func ElemMatch

func ElemMatch(name string, query ...Expr) *field

func Eq

func Eq(name string, value any) *field

func ErrorStreamServerInterceptor

func ErrorStreamServerInterceptor() grpc.StreamServerInterceptor

func ErrorUnaryServerInterceptor

func ErrorUnaryServerInterceptor() grpc.UnaryServerInterceptor

func Exists

func Exists(name string, value bool) *field

func FindOptions

func FindOptions(index uint64, size uint32) *options.FindOptions

func GetClient

func GetClient(ctx context.Context, uri string, log zerolog.Logger) *mongo.Client

func GetDB

func GetDB(ctx context.Context, uri string, log zerolog.Logger) *mongo.Database

func GetDBName

func GetDBName(uri string) (string, error)

func Gt

func Gt(name string, value any) *field

func Gte

func Gte(name string, value any) *field

func In

func In(name string, value ...any) *field

func Lt

func Lt(name string, value any) *field

func Lte

func Lte(name string, value any) *field

func Ne

func Ne(name string, value any) *field

func Nin

func Nin(name string, value ...any) *field

func Nor

func Nor(expr ...Expr) *logical

func Not

func Not(name string, expr Expr) *field

func Or

func Or(expr ...Expr) *logical

func Regex

func Regex(name string, pattern string, opts ...string) *field

func Size

func Size(name string, value uint) *field

func ToBson

func ToBson(doc any) (bson.M, error)

Types

type Expr

type Expr interface {
	Build() any
}

type Filter

type Filter []Expr

func (Filter) Build

func (f Filter) Build() any

Jump to

Keyboard shortcuts

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