普通网友 2017-10-17 15:49
浏览 34

将收藏转换为使用mgo封顶

I would like to convert a mongo collection to capped using gopkg.in/mgo.v2.

I am able to create a capped collection from scratch - as follows:

# Create a Capped Collection
sess.DB("").C("my_collection").Create(&mgo.CollectionInfo{Capped: true, MaxBytes: tenMB, MaxDocs: 10})

I can't work out how to get the stats for an existing collection or how to run convertToCapped command.

Step 1 - Get Collection Stats:

# Mongo
db.getCollection('my_collection').stats();

# mgo // I need to find out how to do this.

Step 2 - Convert to Capped

# Mongo
db.runCommand({"convertToCapped": "my_collection", size: 1000000});

# mgo // I need to find out how to do this.
if err := sess.DB("").Run(bson.D{{"convertToCapped", "my_collection"}, {"size", "1000"}}, nil); err != nil {
        println(err.Error()) // invalid command spec
        os.Exit(1)
}
  • 写回答

0条回答 默认 最新

    报告相同问题?