mongodb

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 22, 2019 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Init

func Init()

包初始化时实例化一个mongo session

func M

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

使用示例

定义一个接收器
oneData := make(map[string]interface{})

每执行一个M函数都从连接池拷贝一个连接,闭包内有集合collection的操作句柄实例,直接在闭包里mongo操作
M("student", func(collection *mgo.Collection) {
	err := collection.FindId(bson.ObjectIdHex("5c8608a7baa5203fc198859f")).One(&oneData)
	ErrorHandler(err, "Find().One()")
	fmt.Println("查询一个结果:", oneData)
})

func Session

func Session() *mgo.Session

copy session 实现连接池

Types

This section is empty.

Jump to

Keyboard shortcuts

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