mongo

package module
v0.0.0-...-64b9ef7 Latest Latest
Warning

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

Go to latest
Published: Mar 8, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

mongo

go的mongodb库

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	//ErrNotFound 数据没有找到
	ErrNotFound = mgo.ErrNotFound
)

Functions

func Hex

func Hex(oid ObjectID) string

Hex 返回ObjectId的十六进制

func IsObjectIdHex

func IsObjectIdHex(s string) bool

IsObjectIdHex 返回ObjectId是否为ObjectId的有效十六进制

Types

type Client

type Client struct {
	// contains filtered or unexported fields
}

Client mongodb连接结构体

func Conn

func Conn(urlAddr string) *Client

Conn 连接mongodb

func (*Client) FindAndModify

func (c *Client) FindAndModify(database, collection string, selector, update M, upsert bool, result interface{}) (int, error)

FindAndModify 查找并修改数据

func (*Client) FindAndRemove

func (c *Client) FindAndRemove(database, collection string, selector M, result interface{}) (int, error)

FindAndRemove 查找并删除数据

func (*Client) GetCount

func (c *Client) GetCount(database, collection string, query M) (int, error)

GetCount 返回统计条数

func (*Client) GetPipeResult

func (c *Client) GetPipeResult(database, collection string, pipeline []M, result *[]M) error

GetPipeResult 使用管道进行聚合计算并返回多行结果集

func (*Client) GetPipeRow

func (c *Client) GetPipeRow(database, collection string, pipeline []M, result *M) error

GetPipeRow 使用管道进行聚合计算并返回一行数据

func (*Client) GetResult

func (c *Client) GetResult(database, collection string, query, fields, options M, result interface{}) error

GetResult 返回多行结果集

func (*Client) GetRow

func (c *Client) GetRow(database, collection string, query, options M, result interface{}) error

GetRow 返回一行数据

func (*Client) Insert

func (c *Client) Insert(database, collection string, docs ...interface{}) error

Insert 插入数据

func (*Client) Ping

func (c *Client) Ping() error

Ping 监测数据库连接

func (*Client) Remove

func (c *Client) Remove(database, collection string, selector M) error

Remove 删除数据

func (*Client) RemoveAll

func (c *Client) RemoveAll(database, collection string, selector M) (int, error)

RemoveAll 批量删除数据

func (*Client) Update

func (c *Client) Update(database, collection string, selector, update M) error

Update 更新数据,不存在报ErrNotFound

func (*Client) UpdateAll

func (c *Client) UpdateAll(database, collection string, selector, update M) (map[string]interface{}, error)

UpdateAll 批量更新数据,不存在报ErrNotFound

func (*Client) Upsert

func (c *Client) Upsert(database, collection string, selector, update M) (map[string]interface{}, error)

Upsert 更新数据,不存在会新插入数据

type D

type D bson.D

D 自定义bson类型

type M

type M = bson.M

M 自定义bson类型

type ObjectID

type ObjectID = bson.ObjectId

ObjectID 自定义ObjectID类型

func NewObjectID

func NewObjectID() ObjectID

NewObjectID 返回一个新的唯一ObjectId

func ObjectIDHex

func ObjectIDHex(s string) ObjectID

ObjectIDHex 将id转成十六进制表示返回ObjectId

type Sort

type Sort []string

Sort 自定义排序类型

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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