Documentation ¶
Index ¶
- Constants
- Variables
- func BulkWrite(ctx context.Context, c *mongo.Collection, models []mongo.WriteModel, ...) (*mongo.BulkWriteResult, error)
- func Count(ctx context.Context, c *mongo.Collection, filter any, ...) (int64, error)
- func DecodeAll(ctx context.Context, cur *mongo.Cursor, docs any) error
- func DecodeOne(r *mongo.SingleResult, doc any) error
- func Delete(ctx context.Context, c *mongo.Collection, filter any, ...) error
- func DeleteMany(ctx context.Context, c *mongo.Collection, filter any, ...) error
- func Find[T any](ctx context.Context, c *mongo.Collection, filter any, ...) (docs []T, err error)
- func FindByCriteria[T any](ctx context.Context, c *mongo.Collection, criteria Criteria, ...) ([]T, error)
- func FindOne[T any](ctx context.Context, c *mongo.Collection, filter any, ...) (doc T, err error)
- func GetClient(ctx context.Context, uri string) (*mongo.Client, error)
- func GetDB(ctx context.Context, uri string) (*mongo.Database, error)
- func GetDBName(uri string) (string, error)
- func Pagination(index int64, size int64) *options.FindOptions
- func Parse(values url.Values) map[string]Filter
- func Save(ctx context.Context, c *mongo.Collection, filter any, update any, ...) (*mongo.UpdateResult, error)
- func SaveMany(ctx context.Context, c *mongo.Collection, filter any, update any, ...) (*mongo.UpdateResult, error)
- func ToBson(doc any) (bson.M, error)
- type Criteria
- func C(values url.Values, filterName string) Criteria
- func GetC(query, filterName string) (Criteria, error)
- func GetCriteria(query, filterName string) (Criteria, error)
- func MustC(query, filterName string) Criteria
- func MustGetCriteria(query, filterName string) Criteria
- func ToCriteria(values url.Values, filterName string) Criteria
- type Expr
- func All(name string, value ...any) Expr
- func And(expr ...Expr) Expr
- func ElemMatch(name string, query ...Expr) Expr
- func Eq(name string, value any) Expr
- func Exists(name string, value bool) Expr
- func Gt(name string, value any) Expr
- func Gte(name string, value any) Expr
- func In(name string, value ...any) Expr
- func Lt(name string, value any) Expr
- func Lte(name string, value any) Expr
- func Ne(name string, value any) Expr
- func Nin(name string, value ...any) Expr
- func Nor(expr ...Expr) Expr
- func Not(name string, expr Expr) Expr
- func Or(expr ...Expr) Expr
- func Regex(name string, pattern string, opts ...string) Expr
- func Size(name string, value uint) Expr
- type Field
- type Filter
- type Logical
- type Operator
Constants ¶
View Source
const ( QueryIndex = "index" QuerySize = "size" QuerySort = "sort" QuerySortArr = "sort[]" QueryCondition = "condition" QueryField = "field" QueryValue = "value" CondEmpty = "" CondEq = "eq" CondNe = "ne" CondGt = "gt" CondGte = "gte" CondLt = "lt" CondLte = "lte" CondIn = "in" CondNin = "nin" CondRegex = "regex" CondLike = "like" )
View Source
const ( // comparison OpEq = Operator("$eq") OpNe = Operator("$ne") OpGt = Operator("$gt") OpGte = Operator("$gte") OpLt = Operator("$lt") OpLte = Operator("$lte") OpIn = Operator("$in") OpNin = Operator("$nin") // logical OpAnd = Operator("$and") OpOr = Operator("$or") OpNor = Operator("$nor") OpNot = Operator("$not") // array OpAll = Operator("$all") OpSize = Operator("$size") OpElemMatch = Operator("$elemMatch") // element OpExists = Operator("$exists") // evaluation OpRegex = Operator("$regex") )
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 ( DefaultSize = int64(20) Timeout = 5 * time.Second )
View Source
const ErrMsgClient = "failed to create mongodb client due to error: %w"
View Source
const ErrMsgDatabase = "failed to create mongodb database due to error: %w"
Variables ¶
View Source
var ErrNoDB = errors.New("database Name OpNot found in URI")
Functions ¶
func BulkWrite ¶
func BulkWrite(ctx context.Context, c *mongo.Collection, models []mongo.WriteModel, opts ...*options.BulkWriteOptions) (*mongo.BulkWriteResult, error)
func Count ¶
func Count(ctx context.Context, c *mongo.Collection, filter any, opts ...*options.CountOptions) (int64, error)
func Delete ¶
func Delete(ctx context.Context, c *mongo.Collection, filter any, opts ...*options.DeleteOptions) error
func DeleteMany ¶
func DeleteMany(ctx context.Context, c *mongo.Collection, filter any, opts ...*options.DeleteOptions) error
func Find ¶
func Find[T any](ctx context.Context, c *mongo.Collection, filter any, opts ...*options.FindOptions) (docs []T, err error)
func FindByCriteria ¶
func FindByCriteria[T any](ctx context.Context, c *mongo.Collection, criteria Criteria, opts ...*options.FindOptions) ([]T, error)
func FindOne ¶
func FindOne[T any](ctx context.Context, c *mongo.Collection, filter any, opts ...*options.FindOneOptions) (doc T, err error)
func Pagination ¶
func Pagination(index int64, size int64) *options.FindOptions
func Save ¶
func Save(ctx context.Context, c *mongo.Collection, filter any, update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
func SaveMany ¶
func SaveMany(ctx context.Context, c *mongo.Collection, filter any, update any, opts ...*options.UpdateOptions) (*mongo.UpdateResult, error)
Types ¶
type Criteria ¶
func GetCriteria ¶
func MustGetCriteria ¶
MustGetCriteria query example: index=20&size=20&sort[]=sku&sort[]=-amount&filters[0][0][field]=sku&filters[0][0][value]=WSH%2529%25&filters[0][0][condition]=like&filters[0][1][field]=sku&filters[0][1][value]=WP%2529%25&filters[0][1][condition]=like&filters[1][0][field]=price&filters[1][0][value]=40&filters[1][0][condition]=eq&filters[2][0][field]=price&filters[2][0][value]=49.99&filters[2][0][condition]=to
Click to show internal directories.
Click to hide internal directories.