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)
}