使用mgo或bson在Go中重命名mongo集合?

dmo*_*nay 2 go mongodb bson mgo

我想在我的Go应用程序中重命名mongo集合.我正在使用mgo驱动程序,它没有定义的方法来执行此操作.有谁知道查询将使用bson?这是我想在Go中实现的命令:http://docs.mongodb.org/manual/reference/command/renameCollection/

Dan*_*ams 5

我没有使用过mgo,但这看起来就像你想要运行原始查询一样.

http://godoc.org/labix.org/v2/mgo#Session.Run

直接到mongo:

db.adminCommand({renameCollection:'yourdb.yourcollection', to:'yourdb.yournewcollection'})
Run Code Online (Sandbox Code Playgroud)

使用mgo:

session.Run(bson.D{{"renameCollection", "yourdb.yourcollection"}, {"to", "yourdb.yournewcollection"}})
Run Code Online (Sandbox Code Playgroud)