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 求高通平台Softsim调试经验
  • ¥15 canal如何实现将mysql多张表(月表)采集入库到目标表中(一张表)?
  • ¥15 wpf ScrollViewer实现冻结左侧宽度w范围内的视图
  • ¥15 栅极驱动低侧烧毁MOSFET
  • ¥30 写segy数据时出错3
  • ¥100 linux下qt运行QCefView demo报错
  • ¥50 F1C100S下的红外解码IR_RX驱动问题
  • ¥20 基于matlab的航迹融合 航迹关联 航迹插补
  • ¥15 用Matlab实现图中的光线追迹
  • ¥15 联想笔记本开机出现系统更新界面