mongodb

package
v0.0.0-...-af31a00 Latest Latest
Warning

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

Go to latest
Published: Dec 13, 2017 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Delete

func Delete(collectionName string, selector interface{}) error

删除文档

func Exists

func Exists(collectionName string, query bson.M) bool

查询是否存在

func GetSession

func GetSession() *mgo.Session

获取session,返回的是master session的一个副本

func InitMasterSession

func InitMasterSession()

func Insert

func Insert(collectionName string, docs interface{}) error

插入文档

func M

func M(collection string, f func(*mgo.Collection) error) error

执行mongodb shell

func Select

func Select(collectionName string, query bson.M, sort string, fields bson.M, skip int, limit int) (results []interface{}, err error)

*

  • 执行查询,此方法可拆分做为公共方法
  • [Select description]
  • @param {[type]} collectionName string [description]
  • @param {[type]} query bson.M [description]
  • @param {[type]} sort bson.M [description]
  • @param {[type]} fields bson.M [description]
  • @param {[type]} skip int [description]
  • @param {[type]} limit int) (results []interface{}, err error [description]

func SelectAll

func SelectAll(collectionName string, query, fields bson.M, results interface{}) error

查询所有结果 比较常用的查询,只带field筛选条件

func SelectAllWithParam

func SelectAllWithParam(collectionName string, query bson.M, sort string, fields bson.M, skip int, limit int, results interface{}) error

查询所有结果 类似Select方法,需要传入比较详细的参数列表,注意:result 必须传递一个slice指针

func SelectById

func SelectById(collectionName string, id interface{}, fields bson.M, results interface{}) error

根据id查询结果 类似Select方法,注意:result 必须传递一个slice指针

func SelectOne

func SelectOne(collectionName string, query, fields bson.M, results interface{}) error

查询一个结果,如果查询结果超过一个,会报错 类似Select方法,注意:result 必须传递一个slice指针

func Test

func Test()

func Update

func Update(collectionName string, selector interface{}, update interface{}) error

更新文档

func UpdateById

func UpdateById(collectionName string, id interface{}, update interface{}) error

通过Id更新文档

Types

type Account

type Account struct {
	Id_      uint32 `bson:"_id"`
	Account  string `bson:"account"`
	Password string `bson:"password"`
}

///////////////////////////////////////// test

Jump to

Keyboard shortcuts

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