I'd like to rename a mongo collection in my Go app. I'm using the mgo driver and it doesn't have a defined method to do this. Does anyone know what the query would be using bson? This is the command I'd like to implement in Go: http://docs.mongodb.org/manual/reference/command/renameCollection/
1条回答 默认 最新
- douzhouhan4618 2015-01-16 23:24关注
I haven't used mgo but this looks like exactly what you want to run a raw query.
http://godoc.org/labix.org/v2/mgo#Session.Run
In directly to mongo:
db.adminCommand({renameCollection:'yourdb.yourcollection', to:'yourdb.yournewcollection'})
Using mgo:
session.Run(bson.D{{"renameCollection", "yourdb.yourcollection"}, {"to", "yourdb.yournewcollection"}})
本回答被题主选为最佳回答 , 对您是否有帮助呢?解决 无用评论 打赏 举报