mmgo

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

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

Go to latest
Published: Aug 13, 2019 License: GPL-3.0 Imports: 4 Imported by: 0

README

mmgo

opp in mgo package.

mgo package package.

Usage

// NewCtx - (dbName ,collectionName )
var Coll1 = mmgo.NewCtx("test", "coll1")
var Coll2 = mmgo.NewCtx("article", "p1")

func main(){
    Coll1.Insert(bson.M{
		"name": "alice",
		"age":  12,
		"info": "996",
    })
    Coll1.Insert(bson.M{
		"name": "bob",
		"age":  20,
		"info": "996",
    })
    
    var collection = []bson.M
    err := Coll2.FindAll(nil, nil, &collection)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Printf("[LOG] res = %v\n", collection)
}

API_USAGE

NewCtx

top

NewCtx(name, coll string) *MgoDB

var Coll = mmgo.NewCtx("test", "coll1")
SetName_SetCollection

top

SetName(name string)
SetCollection(name string)

var Coll = mmgo.NewCtx("test", "coll")
Coll.SetName("test1")
// Coll.SetCollection("coll")
IsEmpty

top

(m *MgoDB) IsEmpty() bool

var Coll = mmgo.NewCtx("test", "coll")
if Coll.IsEmpty() {
    fmt.Println("coll is empty")
}else{
    fmt.Println("coll is not empty")
}
Count

top

Count(query interface{}) (int, error)

Insert

top

Insert(docs ...interface{}) error

FindOne

top

FindOne(query, selector, result interface{}) error

FindAll

top

FindAll(query, selector, result interface{}) error

FindPage

top

FindPage(page, limit int, query, selector, result interface{}) error

FindIter

top

FindIter(query interface{}) *mgo.Iter

Update

top

Update(selector, update interface{}) error

Upsert

top

Upsert(selector, update interface{}) error

UpdateAll

top

UpdateAll(selector, update interface{}) error

Remove

top

Remove(selector interface{}) error

RemoveAll

top

RemoveAll(selector interface{}) error

RemoveRepeat

top

RemoveRepeat(selector interface{})

RemoveRepeatByKey

top

RemoveRepeatByKey(key string)

BulkInsert

top

BulkInsert(docs ...interface{}) (*mgo.BulkResult, error)

BulkRemove

top

BulkRemove(selector ...interface{}) (*mgo.BulkResult, error)

BulkRemoveAll

top

BulkRemoveAll(selector ...interface{}) (*mgo.BulkResult, error)

BulkUpdate

top

BulkUpdate(pairs ...interface{}) (*mgo.BulkResult, error)

BulkUpdateAll

top

BulkUpdateAll(pairs ...interface{}) (*mgo.BulkResult, error)

BulkUpsert

top

BulkUpsert(pairs ...interface{}) (*mgo.BulkResult, error)

PipeAll

top

PipeAll(pipeline, result interface{}, allowDiskUse bool) error

PipeOne

top

PipeOne(pipeline, result interface{}, allowDiskUse bool) error

PipeIter

top

PipeIter(pipeline interface{}, allowDiskUse bool) *mgo.Iter

Explain

top

Explain(pipeline, result interface{}) error

GridFSCreate

top

GridFSCreate(prefix, name string) (*mgo.GridFile, error)

GridFSFindOne

top

GridFSFindOne(prefix string, query, result interface{}) error

GridFSFindAll

top

GridFSFindAll(prefix string, query, result interface{}) error

GridFSOpen

top

GridFSOpen(prefix, name string) (*mgo.GridFile, error)

GridFSRemove

top

GridFSRemove(prefix, name string) error

LICENSE

GPL-3.0

Documentation

Index

Constants

View Source
const (
	PoolLimit = 4096
)

Variables

This section is empty.

Functions

This section is empty.

Types

type MgoDB

type MgoDB struct {
	CurrentDBname       string
	CurrentDBcollection string
	// contains filtered or unexported fields
}

mgo object 储存数据库访问的上下文

func NewCtx

func NewCtx(name, coll string) *MgoDB

create new context 参数分别是数据库key值,和集合名称

func (*MgoDB) BulkInsert

func (m *MgoDB) BulkInsert(docs ...interface{}) (*mgo.BulkResult, error)

insert one or multi documents

func (*MgoDB) BulkRemove

func (m *MgoDB) BulkRemove(selector ...interface{}) (*mgo.BulkResult, error)

func (*MgoDB) BulkRemoveAll

func (m *MgoDB) BulkRemoveAll(selector ...interface{}) (*mgo.BulkResult, error)

func (*MgoDB) BulkUpdate

func (m *MgoDB) BulkUpdate(pairs ...interface{}) (*mgo.BulkResult, error)

func (*MgoDB) BulkUpdateAll

func (m *MgoDB) BulkUpdateAll(pairs ...interface{}) (*mgo.BulkResult, error)

func (*MgoDB) BulkUpsert

func (m *MgoDB) BulkUpsert(pairs ...interface{}) (*mgo.BulkResult, error)

func (*MgoDB) Count

func (m *MgoDB) Count(query interface{}) (int, error)

根据查询返回个数

func (*MgoDB) Explain

func (m *MgoDB) Explain(pipeline, result interface{}) error

func (*MgoDB) FindAll

func (m *MgoDB) FindAll(query, selector, result interface{}) error

func (*MgoDB) FindIter

func (m *MgoDB) FindIter(query interface{}) (*mgo.Iter, error)

func (*MgoDB) FindOne

func (m *MgoDB) FindOne(query, selector, result interface{}) error

func (*MgoDB) FindPage

func (m *MgoDB) FindPage(page, limit int, query, selector, result interface{}) error

func (*MgoDB) FindPageReverse

func (m *MgoDB) FindPageReverse(page, limit int, query, selector, result interface{}) error

func (*MgoDB) GridFSCreate

func (m *MgoDB) GridFSCreate(prefix, name string) (*mgo.GridFile, error)

func (*MgoDB) GridFSFindAll

func (m *MgoDB) GridFSFindAll(prefix string, query, result interface{}) error

func (*MgoDB) GridFSFindOne

func (m *MgoDB) GridFSFindOne(prefix string, query, result interface{}) error

func (*MgoDB) GridFSOpen

func (m *MgoDB) GridFSOpen(prefix, name string) (*mgo.GridFile, error)

func (*MgoDB) GridFSRemove

func (m *MgoDB) GridFSRemove(prefix, name string) error

func (*MgoDB) Insert

func (m *MgoDB) Insert(docs ...interface{}) error

插入操作,可一次插入多个文档

func (*MgoDB) IsEmpty

func (m *MgoDB) IsEmpty() bool

return collection ture/false rmpty 判断是否在操作一个空集合

func (*MgoDB) IsLive

func (m *MgoDB) IsLive() bool

return mgo context context state 判断能否与数据库连接

func (*MgoDB) PipeAll

func (m *MgoDB) PipeAll(pipeline, result interface{}, allowDiskUse bool) error

func (*MgoDB) PipeIter

func (m *MgoDB) PipeIter(pipeline interface{}, allowDiskUse bool) (*mgo.Iter, error)

func (*MgoDB) PipeOne

func (m *MgoDB) PipeOne(pipeline, result interface{}, allowDiskUse bool) error

func (*MgoDB) Remove

func (m *MgoDB) Remove(selector interface{}) error

func (*MgoDB) RemoveAll

func (m *MgoDB) RemoveAll(selector interface{}) error

func (*MgoDB) RemoveRepeat

func (m *MgoDB) RemoveRepeat(selector interface{})

func (*MgoDB) RemoveRepeatByKey

func (m *MgoDB) RemoveRepeatByKey(key string)

func (*MgoDB) SetCollection

func (m *MgoDB) SetCollection(name string)

change db context collection name 修改数据库名称,除特殊不建议使用

func (*MgoDB) SetName

func (m *MgoDB) SetName(name string)

change db context db name 修改数据库名称,除特殊不建议使用

func (*MgoDB) Update

func (m *MgoDB) Update(selector, update interface{}) error

func (*MgoDB) UpdateAll

func (m *MgoDB) UpdateAll(selector, update interface{}) error

func (*MgoDB) Upsert

func (m *MgoDB) Upsert(selector, update interface{}) error

Jump to

Keyboard shortcuts

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