# README
mongoDB
对mongoDB关于MongoDB的一些基础操作做一下封装,便于直接调用
- 插入一个或多个
document
func Insert(db, collection string, docs ...interface{}) error
- 查询一个满足条件的
document
query查询条件 bson.M{"_id":"id"}
selector相当于MongoDB中的projection,查询结果中是否显示某个字段 bson.M{"_id":0}
func FindOne(db, collection string, query, selector, result interface{}) error
- 查询满足条件的所有结果
func FindAll(db, collection string, query, selector, result interface{}) error
- 对查询结果分页处理
func FindPage(db, collection string, page, limit int, query, selector, result interface{}) error
- 查询满足条件的
cursor
func FindIter(db, collection string, query interface{}) *mgo.Iter
- 更新满足条件的一个
document
func Update(db, collection string, selector, update interface{}) error
- 更新满足条件的所有的
docuement
func UpdateAll(db, collection string, selector, update interface{}) error
- 更新,如果不存在就插入一个新的
document
func Upsert(db, collection string, selector, update interface{}) error
- 删除满足条件的一个
document
func Remove(db, collection string, selector interface{}) error
- 删除满足条件的所有的
document
func RemoveAll(db, collection string, selector interface{}) error
- 批量的插入
func BulkInsert(db, collection string, docs ...interface{}) (*mgo.BulkResult, error)
- 批量更新
func BulkUpdate(db, collection string, pairs ...interface{}) (*mgo.BulkResult, error)
- 批量更新所有
func BulkUpdateAll(db, collection string, pairs ...interface{}) (*mgo.BulkResult, error)
- 批量删除
func BulkRemove(db, collection string, selector ...interface{}) (*mgo.BulkResult, error)
- 批量删除所有
func BulkRemoveAll(db, collection string, selector ...interface{}) (*mgo.BulkResult, error)
- 聚合操作查找所有的
func PipeAll(db, collection string, pipeline, result interface{}, allowDiskUse bool) error
- 聚合操作查找一个
func PipeOne(db, collection string, pipeline, result interface{}, allowDiskUse bool) error
- 聚合操作查找
cursor
func PipeIter(db, collection string, pipeline interface{}, allowDiskUse bool) *mgo.Iter
- Document是否为空
func IsEmpty(db, collection string) bool
- 查询满足条件的数量
func Count(db, collection string, query interface{}) (int, error)
# Functions
insert one or multi documents.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
db:操作的数据库
collection:操作的文档(表)
query:查询条件
selector:需要过滤的数据(projection)
result:查询到的结果
*/.
err = db.Remove(database,collection,bson.M{"_id":"5b3c30639d5e3e24b8786540"})
*/.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
每次操作之后都要主动关闭 Session defer Session.Close()
db:操作的数据库
collection:操作的文档(表)
doc:要插入的数据
*/.
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
设置索引
*/.
db:操作的数据库
collection:操作的文档(表)
selector:更新条件
update:更新的操作
*/.
`multi:true`.
更新,如果不存在就插入一个新的数据 `upsert:true`.
# Variables
No description provided by the author