本文整理汇总了Golang中labix/org/v2/mgo.Database.Run方法的典型用法代码示例。如果您正苦于以下问题:Golang Database.Run方法的具体用法?Golang Database.Run怎么用?Golang Database.Run使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类labix/org/v2/mgo.Database
的用法示例。
在下文中一共展示了Database.Run方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: IsTokuMX
// IsTokuMX determines if the server connected to is TokuMX.
func IsTokuMX(db *mgo.Database) bool {
var result bson.M
if err := db.Run("buildInfo", &result); err != nil {
log.Fatal(err)
}
return result["tokumxVersion"] != nil
}
示例2: createMongoCollection
// creates a collection in MongoDB
func createMongoCollection(collname string, db *mgo.Database) {
fmt.Println("creating collection: ", collname)
var result bson.M
createCmd := createCollOptions{Coll: collname}
err := db.Run(createCmd, &result)
if err != nil {
log.Fatal(err)
}
}
示例3: applyTokuIndexOptions
func applyTokuIndexOptions(db *mgo.Database, collname string, options tokuMXCreateOptions) {
var result bson.M
var optBson bson.M
optBson = bson.M{"compression": options.CompressionType, "pageSize": options.NodeSize, "readPageSize": options.BasementSize}
err := db.Run(bson.D{{"reIndex", collname}, {"index", "*"}, {"options", optBson}}, &result)
if err != nil {
log.Fatal("Failed to set options on indexes, received ", err)
}
}
示例4: GetDbStats
// Returns a variety of database statistics.
//
// Based on
// http://docs.mongodb.org/manual/reference/command/dbStats/#dbcmd.dbStats
func GetDbStats(db *mgo.Database) (DbStats, error) {
var output DbStats
err := db.Run(bson.D{
{"dbStats", 1},
{"scale", 1},
}, &output)
if err != nil {
return output, err
}
return output, nil
}
示例5: GetCollectionStats
// Returns a variety of storage statistics for a given collection.
//
// Based on
// http://docs.mongodb.org/manual/reference/method/db.collection.stats/
func GetCollectionStats(db *mgo.Database, collectionName string) (CollectionStats, error) {
var output CollectionStats
err := db.Run(bson.D{
{"collStats", collectionName},
{"scale", 1},
{"verbose", true},
}, &output)
if err != nil {
return output, err
}
return output, nil
}
示例6: createTokuCollection
// creates a collection in TokuMX
func createTokuCollection(collname string, db *mgo.Database, options tokuMXCreateOptions) {
fmt.Println("creating collection ", collname)
var result bson.M
createCmd := createCollOptions{
Coll: collname,
Compression: options.CompressionType,
NodeSize: options.NodeSize,
BasementSize: options.BasementSize,
Partitioned: options.Partitioned}
err := db.Run(createCmd, &result)
if err != nil {
log.Fatal(err)
}
}
示例7: GetCollectionNames
// Returns a slice containing the names of all collections in the current database.
//
// Based on
// http://docs.mongodb.org/manual/reference/method/db.getCollectionNames/
func GetCollectionNames(db *mgo.Database) ([]string, error) {
raw := make(map[string]interface{})
err := db.Run(bson.D{{"listCollections", 1}}, &raw)
if err != nil {
return nil, err
}
jq := jsonq.NewQuery(raw)
items, err := jq.ArrayOfObjects("cursor", "firstBatch")
if err != nil {
return nil, err
}
output := make([]string, len(items))
for k, v := range items {
output[k], _ = v["name"].(string)
}
return output, nil
}