mongo

package
v0.0.0-...-9e8b3cb Latest Latest
Warning

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

Go to latest
Published: Jun 11, 2019 License: MIT Imports: 6 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ErrExistConnectionDB      = "exist connection db"
	ErrNoConnection           = "no connection"
	ErrCannotSwitchCollection = "can not switch collection"
	ErrMongoObjDestroyed      = "the mongo object has been destoryed"
)
View Source
const (
	IncrementIdsStarValue = 10000
)

Variables

View Source
var (
	IncrementDBStarId int64 = IncrementIdsStarValue
)

Functions

func BulkInsert

func BulkInsert(db, collection string, docs ...interface{}) (*mgo.BulkResult, error)

insert one or multi documents

func BulkRemove

func BulkRemove(db, collection string, selector ...interface{}) (*mgo.BulkResult, error)

func BulkRemoveAll

func BulkRemoveAll(db, collection string, selector ...interface{}) (*mgo.BulkResult, error)

func BulkUpdate

func BulkUpdate(db, collection string, pairs ...interface{}) (*mgo.BulkResult, error)

func BulkUpdateAll

func BulkUpdateAll(db, collection string, pairs ...interface{}) (*mgo.BulkResult, error)

func BulkUpsert

func BulkUpsert(db, collection string, pairs ...interface{}) (*mgo.BulkResult, error)

func Collection

func Collection(db, collection string) (*mgo.Session, *mgo.Collection)

func EqualError

func EqualError(err error, str string) bool

func Explain

func Explain(db, collection string, pipeline, result interface{}) error

func FindAll

func FindAll(db, collection string, query, selector, results interface{}) error

func FindIter

func FindIter(db, collection string, query interface{}) *mgo.Iter

func FindOne

func FindOne(db, collection string, query, selector, result interface{}) error

func FindPage

func FindPage(db, collection string, page, limit int, query, selector, results interface{}, fields ...string) error

func GetIncrementId

func GetIncrementId(dbName, incrementName string) (int64, error)

func GridFSCreate

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

func GridFSFindAll

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

func GridFSFindOne

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

func GridFSOpen

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

func GridFSRemove

func GridFSRemove(db, prefix, name string) error

func Insert

func Insert(db, collection string, docs ...interface{}) error

func IsExist

func IsExist(db, collection string, query interface{}) bool

func PipeAll

func PipeAll(db, collection string, pipeline, result interface{}, allowDiskUse bool) error

func PipeIter

func PipeIter(db, collection string, pipeline interface{}, allowDiskUse bool) *mgo.Iter

func PipeOne

func PipeOne(db, collection string, pipeline, result interface{}, allowDiskUse bool) error

func RegisterMongo

func RegisterMongo(url, db string) error

RegisterMongo register a mongodb connection. alias is connection's alias url is connection url db is connection's default database name

func Remove

func Remove(db, collection string, selector interface{}) error

func RemoveAll

func RemoveAll(db, collection string, selector interface{}) error

func SetIncrementDBStarId

func SetIncrementDBStarId(startId int64)

func TotalCount

func TotalCount(db, collection string, query, selector interface{}) (int, error)

func Update

func Update(db, collection string, selector, update interface{}, filterNull bool) error

filterNull: 过滤空值对象。空值对象不更新

func UpdateAll

func UpdateAll(db, collection string, selector, data interface{}, filterNull bool) (changInfo *mgo.ChangeInfo, err error)

selector := bson.M{"name": "Tom"} data := bson.M{"$set": bson.M{"age": 22}} filterNull: 过滤空值对象。空值对象不更新

Types

type Monger

type Monger interface {
	IsDestroyed() bool
	Destroy()
	Use(db string) error
	Session() *mgo.Session
	CurrentDB() string
	Collection(c string) *mgo.Collection

	// CURD
	Insert(collection string, docs ...interface{}) (interface{}, error)
	Update(collection string, selector interface{}, update interface{}) error
	FindOne(collection string, query interface{}, result interface{}) (interface{}, error)
	FindAll(collection string, query interface{}, results interface{}) ([]interface{}, error)
	Remove(collection string, selector interface{}) error
	RemoveAll(collection string, selector interface{}) error
}

Jump to

Keyboard shortcuts

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