mongo

package
v0.0.0-...-91d00df Latest Latest
Warning

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

Go to latest
Published: Dec 29, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

View Source
const (
	SORT_UP   = 1
	SORT_DOWN = -1
)

Variables

View Source
var (
	LIMIT                              = int64(1000)
	UPSERT                             = true
	RER_NEW_DOC options.ReturnDocument = options.After
)

Functions

This section is empty.

Types

type Client

type Client struct {
	Cli     *mongo.Client
	Collect map[string]*MCollection
	// contains filtered or unexported fields
}

func New

func New(ctx context.Context, uri string) (*Client, error)

func (*Client) AddCollection

func (c *Client) AddCollection(keyName, DB, colleName string) error

keyName is unique name fo client

func (*Client) Collection

func (c *Client) Collection(keyName string) *MCollection

type Filter

type Filter map[string]interface{}

func NewFilter

func NewFilter() *Filter

func (*Filter) AND

func (f *Filter) AND(filters ...Filter) *Filter

func (*Filter) Equal

func (f *Filter) Equal(field string, val interface{}) *Filter

func (*Filter) GreatEqualThan

func (f *Filter) GreatEqualThan(field string, val interface{}) *Filter

val is int or float ; like age >=10

func (*Filter) GreatThan

func (f *Filter) GreatThan(field string, val interface{}) *Filter

val is int or float

func (*Filter) In

func (f *Filter) In(field string, val []interface{}) *Filter

func (*Filter) LessEqualThan

func (f *Filter) LessEqualThan(field string, val interface{}) *Filter

val is int or float

func (*Filter) LessThan

func (f *Filter) LessThan(field string, val interface{}) *Filter

val is int or float

func (*Filter) Like

func (f *Filter) Like(field string, val string) *Filter

func (*Filter) LikeBack

func (f *Filter) LikeBack(field string, val string) *Filter

like ???a

func (*Filter) LikeFront

func (f *Filter) LikeFront(field string, val string) *Filter

like a???

func (*Filter) NotIn

func (f *Filter) NotIn(field string, vals []interface{}) *Filter

func (*Filter) OR

func (f *Filter) OR(filters ...Filter) *Filter

func (*Filter) Values

func (f *Filter) Values() Filter

type M

type M bson.M

type MCollection

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

func (*MCollection) Aggregate

func (mc *MCollection) Aggregate(ctx context.Context, pipeline interface{}, results interface{}) error

[

{ $match : { score : { $gt : 70, $lte : 90 } } },
{ $group: { _id: null, count: { $sum: 1 } } }

] *

func (*MCollection) DeleteByCondition

func (mc *MCollection) DeleteByCondition(ctx context.Context, filter Filter) (int64, error)

func (*MCollection) DeleteByID

func (mc *MCollection) DeleteByID(ctx context.Context, id string) (int64, error)

func (*MCollection) DeleteByIDs

func (mc *MCollection) DeleteByIDs(ctx context.Context, ids []string) (int64, error)

func (*MCollection) FindAll

func (mc *MCollection) FindAll(ctx context.Context, filter Filter, results interface{}) error

results is addr,default limit=1000

func (*MCollection) FindAllWithOptions

func (mc *MCollection) FindAllWithOptions(ctx context.Context, filter Filter, results interface{}, sortOpt interface{}, limitOpt int64, skipOpt int64) error

- results is addr - sortOpt=nil ==>no sort; - skipOpt=0 ==>no skip - sortOpt=0 ==>no sort ;sortOpt like bson.M{"age": 1} *

func (*MCollection) FindByID

func (mc *MCollection) FindByID(ctx context.Context, id string, result interface{}) error

func (*MCollection) FindOne

func (mc *MCollection) FindOne(ctx context.Context, filter Filter, result interface{}) error

func (*MCollection) GetCount

func (mc *MCollection) GetCount(ctx context.Context, filter interface{}) (int64, error)

func (*MCollection) IncByID

func (mc *MCollection) IncByID(ctx context.Context, id string, update interface{}, result interface{}) error

return new val

func (*MCollection) IncOneByCondition

func (mc *MCollection) IncOneByCondition(ctx context.Context, filter Filter, update interface{}, result interface{}) error

return new val ;only update one collection

func (*MCollection) InsertAll

func (mc *MCollection) InsertAll(ctx context.Context, documents ...interface{}) (bool, error)

not Transaction 不支持事务特性

func (*MCollection) InsertOne

func (mc *MCollection) InsertOne(ctx context.Context, document interface{}) (bool, error)

func (*MCollection) UpdateByCondition

func (mc *MCollection) UpdateByCondition(ctx context.Context, filter Filter, update interface{}) (int64, error)

func (*MCollection) UpdateByID

func (mc *MCollection) UpdateByID(ctx context.Context, id string, update interface{}) (int64, error)

type PipM

type PipM map[string]interface{}

func NewPipM

func NewPipM() *PipM

func (*PipM) Avg

func (pm *PipM) Avg(avgName string, val interface{}) *PipM

val like 1,'$age' ,选择任意字段求平均值

func (*PipM) GroupField

func (pm *PipM) GroupField(groupFieldName, groupField string) *PipM

pip := []bson.M{{"$group": bson.M{"_id": "$age", "total": bson.M{"$sum": 1}}}} groupField 需要分组的字段,groupFieldName,给予命名

func (*PipM) Max

func (pm *PipM) Max(sumName string, val interface{}) *PipM

val like 1,'$age' ,选择任意字段求最大值

func (*PipM) Min

func (pm *PipM) Min(minName string, val interface{}) *PipM

val like 1,'$age' ,选择任意字段求最小值

func (*PipM) Sum

func (pm *PipM) Sum(sumName string, val interface{}) *PipM

val like 1,'$age' ,选择任意字段求和

func (*PipM) Values

func (pm *PipM) Values() PipM

type Pipeline

type Pipeline []map[string]interface{}

func NewPipeline

func NewPipeline() *Pipeline

func (*Pipeline) Group

func (p *Pipeline) Group(pipM PipM) *Pipeline

pipM use pipM Type

func (*Pipeline) Match

func (p *Pipeline) Match(matchFilter Filter) *Pipeline

matchFilter use Filter Type ,if neet match ,the func must executed first

func (*Pipeline) Values

func (p *Pipeline) Values() Pipeline

type Update

type Update map[string]interface{}

func NewUpdate

func NewUpdate() *Update

func (*Update) CurrentDateUpdate

func (u *Update) CurrentDateUpdate(field string) *Update

updateNowTime

func (*Update) Inc

func (u *Update) Inc(cond bson.M) *Update

++ or -- cond like { quantity: -2, "metrics.orders": 1 } key-- {quantity: -2}

func (*Update) Set

func (u *Update) Set(val bson.M) *Update

func (*Update) UnSet

func (u *Update) UnSet(field ...string) *Update

delete field no exception if field not exits

func (*Update) Values

func (u *Update) Values() Update

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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