dongzhong5756 2015-01-16 23:06
浏览 117
已采纳

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

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"}})
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 给出完整的python代码并解释
  • ¥15 有人懂怎么做大模型的客服系统吗?卡住了卡住了
  • ¥20 firefly-rk3399上启动卡住了
  • ¥15 如何删除这个虚拟音频
  • ¥50 hyper默认的default switch
  • ¥15 网站打不开,提示502 Bad Gateway
  • ¥20 基于MATLAB的绝热压缩空气储能系统代码咨询
  • ¥15 R语言建立随机森林模型出现的问题
  • ¥15 关于#wpf#的问题:怎么更改LayoutGroup组件的标签页的字体颜色
  • ¥15 中级微观经济学,生产可能性边界问题