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

报告相同问题?