Documentation ¶
Index ¶
- func C(c interface{}) (*mgo.Collection, error)
- func Config(name ...string) *xmgoConfig
- func Drop(c interface{}) error
- func FindById(c interface{}, id interface{}, selects ...map[string]interface{}) (interface{}, error)
- func FindOne(c interface{}, where map[string]interface{}, selects ...interface{}) (interface{}, error)
- func Insert(c interface{}, docs map[string]interface{}) error
- func Query(c interface{}, where map[string]interface{}) (*mgo.Query, error)
- func Update(c interface{}, where map[string]interface{}, data interface{}) error
- func UpdateAll(c interface{}, where map[string]interface{}, data interface{}) (*mgo.ChangeInfo, error)
- func UpdateById(c interface{}, id interface{}, data interface{}) error
- type Ixmgo
- type IxmgoCollection
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Drop ¶
func Drop(c interface{}) error
删除集合
Example ¶
删除集合
err := Drop("test") fmt.Printf("drop err:%v", err)
Output:
func FindById ¶
func FindById(c interface{}, id interface{}, selects ...map[string]interface{}) (interface{}, error)
根据id查找记录
Example ¶
one, err := FindById("test", testId) fmt.Printf("findById result:%v err:%v\n", one, err)
Output:
func FindOne ¶
func FindOne(c interface{}, where map[string]interface{}, selects ...interface{}) (interface{}, error)
获取一条数据
Example ¶
one, err := FindOne("test", nil) fmt.Printf("findOne result:%v err:%v\n", one, err)
Output:
func Insert ¶
添加记录
Example ¶
err := Insert("test", map[string]interface{}{ "_id": testId, "name": "张三", "age": 32, "birthday": time.Now(), "audit": true, }) fmt.Printf("insert err:%v\n", err)
Output:
func Query ¶
查询数据
Example ¶
query, err := Query("test", nil) if err != nil { fmt.Printf("query err:%v\n", err) } var rows []map[string]interface{} err = query.Select(map[string]interface{}{ "name": 1, "age": 1, }).All(&rows) fmt.Printf("query rows:%v, err:%v\n", rows, err)
Output:
func UpdateAll ¶
func UpdateAll(c interface{}, where map[string]interface{}, data interface{}) (*mgo.ChangeInfo, error)
更新所有记录
func UpdateById ¶
func UpdateById(c interface{}, id interface{}, data interface{}) error
根据ID更新记录
Example ¶
err := UpdateById("test", testId, bson.M{ "name": "李四", "age": 18, }) fmt.Printf("updateById result err:%v", err)
Output:
Types ¶
Click to show internal directories.
Click to hide internal directories.