英文:
Rename mongo collection in Go using mgo or bson?
问题
我可以帮你翻译这段内容。以下是翻译结果:
我想在我的Go应用程序中重命名一个Mongo集合。我正在使用mgo驱动程序,但它没有定义的方法来执行此操作。有人知道使用bson的查询应该是什么吗?这是我想在Go中实现的命令:http://docs.mongodb.org/manual/reference/command/renameCollection/
英文:
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
得分: 6
我还没有使用过mgo,但这看起来正是你想要运行原始查询的方法。
http://godoc.org/labix.org/v2/mgo#Session.Run
直接在mongo中执行:
db.adminCommand({renameCollection:'yourdb.yourcollection', to:'yourdb.yournewcollection'})
使用mgo:
session.Run(bson.D{{"renameCollection", "yourdb.yourcollection"}, {"to", "yourdb.yournewcollection"}})
英文:
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"}})
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论