Documentation ¶
Index ¶
- Constants
- Variables
- type Client
- type Filter
- func (f *Filter) AND(filters ...Filter) *Filter
- func (f *Filter) Equal(field string, val interface{}) *Filter
- func (f *Filter) GreatEqualThan(field string, val interface{}) *Filter
- func (f *Filter) GreatThan(field string, val interface{}) *Filter
- func (f *Filter) In(field string, val []interface{}) *Filter
- func (f *Filter) LessEqualThan(field string, val interface{}) *Filter
- func (f *Filter) LessThan(field string, val interface{}) *Filter
- func (f *Filter) Like(field string, val string) *Filter
- func (f *Filter) LikeBack(field string, val string) *Filter
- func (f *Filter) LikeFront(field string, val string) *Filter
- func (f *Filter) NotIn(field string, vals []interface{}) *Filter
- func (f *Filter) OR(filters ...Filter) *Filter
- func (f *Filter) Values() Filter
- type M
- type MCollection
- func (mc *MCollection) Aggregate(ctx context.Context, pipeline interface{}, results interface{}) error
- func (mc *MCollection) DeleteByCondition(ctx context.Context, filter Filter) (int64, error)
- func (mc *MCollection) DeleteByID(ctx context.Context, id string) (int64, error)
- func (mc *MCollection) DeleteByIDs(ctx context.Context, ids []string) (int64, error)
- func (mc *MCollection) FindAll(ctx context.Context, filter Filter, results interface{}) error
- func (mc *MCollection) FindAllWithOptions(ctx context.Context, filter Filter, results interface{}, sortOpt interface{}, ...) error
- func (mc *MCollection) FindByID(ctx context.Context, id string, result interface{}) error
- func (mc *MCollection) FindOne(ctx context.Context, filter Filter, result interface{}) error
- func (mc *MCollection) GetCount(ctx context.Context, filter interface{}) (int64, error)
- func (mc *MCollection) IncByID(ctx context.Context, id string, update interface{}, result interface{}) error
- func (mc *MCollection) IncOneByCondition(ctx context.Context, filter Filter, update interface{}, result interface{}) error
- func (mc *MCollection) InsertAll(ctx context.Context, documents ...interface{}) (bool, error)
- func (mc *MCollection) InsertOne(ctx context.Context, document interface{}) (bool, error)
- func (mc *MCollection) UpdateByCondition(ctx context.Context, filter Filter, update interface{}) (int64, error)
- func (mc *MCollection) UpdateByID(ctx context.Context, id string, update interface{}) (int64, error)
- type PipM
- func (pm *PipM) Avg(avgName string, val interface{}) *PipM
- func (pm *PipM) GroupField(groupFieldName, groupField string) *PipM
- func (pm *PipM) Max(sumName string, val interface{}) *PipM
- func (pm *PipM) Min(minName string, val interface{}) *PipM
- func (pm *PipM) Sum(sumName string, val interface{}) *PipM
- func (pm *PipM) Values() PipM
- type Pipeline
- type Update
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 (*Client) AddCollection ¶
keyName is unique name fo client
func (*Client) Collection ¶
func (c *Client) Collection(keyName string) *MCollection
type Filter ¶
type Filter map[string]interface{}
func (*Filter) GreatEqualThan ¶
val is int or float ; like age >=10
func (*Filter) LessEqualThan ¶
val is int or float
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 (*MCollection) DeleteByID ¶
func (*MCollection) DeleteByIDs ¶
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 (*MCollection) UpdateByID ¶
type PipM ¶
type PipM map[string]interface{}
func (*PipM) GroupField ¶
pip := []bson.M{{"$group": bson.M{"_id": "$age", "total": bson.M{"$sum": 1}}}} groupField 需要分组的字段,groupFieldName,给予命名
type Pipeline ¶
type Pipeline []map[string]interface{}
func NewPipeline ¶
func NewPipeline() *Pipeline
Click to show internal directories.
Click to hide internal directories.