mongo

package
v1.0.1 Latest Latest
Warning

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

Go to latest
Published: Oct 21, 2020 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func All

func All(db *mgo.Database, collection string, query interface{}, result interface{}) error

func AllSelect

func AllSelect(db *mgo.Database, collection string, query interface{}, projection interface{}, result interface{}) error

返回所有复合 query 条件的item, 并且被 projection 限制返回的fields

func Count

func Count(db *mgo.Database, collection string, query interface{}) (n int)

func CountId

func CountId(db *mgo.Database, collection string, id interface{}) (n int)

func Exec

func Exec(db *mgo.Database, callback func(*mgo.Database) error) error

func Exist

func Exist(db *mgo.Database, collection string, query interface{}) bool

func ExistId

func ExistId(db *mgo.Database, collection string, id interface{}) bool

func FindId

func FindId(db *mgo.Database, collection string, id interface{}, result interface{}) error

func Insert

func Insert(db *mgo.Database, collection string, data ...interface{}) error

func NewMdb

func NewMdb(host, port, database, userName, password string) (*mgo.Database, error)

func NewMdbWithURL

func NewMdbWithURL(url string) (*mgo.Database, error)

func One

func One(db *mgo.Database, collection string, query interface{}, result interface{}) error

func OneSelect

func OneSelect(db *mgo.Database, collection string, query interface{}, projection interface{}, result interface{}) error

func Page

func Page(db *mgo.Database, collection string, query bson.M, offset int, limit int, result interface{}) error

func PageAndCount

func PageAndCount(db *mgo.Database, collection string, query bson.M, offset int, limit int, result interface{}) (total int, err error)

获取页面数据和“所有”符合条件的记录“总共”的条数

func Remove

func Remove(db *mgo.Database, collection string, selector interface{}) error

func RemoveAll

func RemoveAll(db *mgo.Database, collection string, selector interface{}) error

func RemoveId

func RemoveId(db *mgo.Database, collection string, id interface{}) error

func SetId

func SetId(db *mgo.Database, collection string, id interface{}, change interface{}) error

等同与UpdateId(db *mgo.Database, collection,id,bson.M{"$set":change})

func Update

func Update(db *mgo.Database, collection string, selector, change interface{}) error

func UpdateAll

func UpdateAll(db *mgo.Database, collection string, selector, change interface{}) error

func UpdateId

func UpdateId(db *mgo.Database, collection string, id interface{}, change interface{}) error

func Upsert

func Upsert(db *mgo.Database, collection string, selector interface{}, change interface{}) error

func WithC

func WithC(db *mgo.Database, collection string, job func(*mgo.Collection) error) error

Types

type Config

type Config struct {
	Host     string
	Port     string
	UserName string
	Password string
	Database string
}

type MgoIndexs

type MgoIndexs map[string][]mgo.Index

func (MgoIndexs) Setup

func (m MgoIndexs) Setup(db *mgo.Database) error

Jump to

Keyboard shortcuts

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