简体   繁体   English

分片中的MongoDB重命名集合

[英]MongoDB Rename collection in Sharding

How can I rename a collection in mongodb sharding? 如何在mongodb分片中重命名集合? Because I tried in my production server, its thrown the following error just for your references. 由于我在生产服务器中尝试过,因此它抛出以下错误,仅供您参考。

My Requirement we have to add few more fields with value on existing collection. 我的要求是,我们必须在现有集合上添加更多具有价值的字段。 But In production we can't able to disrupt the traffic based collection and anytime request comes from member simultaneously. 但是在生产中,我们无法中断基于流量的收集,并且任何时候都可能同时收到成员的请求。 So we have planned to populate the entire records from sql to mongo in another collection and then rename the collection and make it as production. 因此,我们计划在另一个集合中填充从sql到mongo的全部记录,然后重命名该集合并将其作为生产。 its our plan. 这是我们的计划。 But we cant able to take it further. 但是我们无法进一步发展。 Following error we got it. 跟随错误我们明白了。

db.clientdetails.renameCollection( "clientdetails_bkup" ); {
            "assertion" : "You can't rename a sharded collection",
            "assertionCode" : 13138,
            "errmsg" : "db assertion failure",
            "ok" : 0 }

If not possible in mongodb sharding, please share your suggestion or alternative way we can solve this issue. 如果无法在mongodb分片中使用,请分享您的建议或我们可以解决此问题的替代方法。

Please suggest what we have to take it further?. 请提出进一步的建议。

There is no way to rename a sharded collection. 无法重命名分片集合。

You can copy all the docs to a new collection. 您可以将所有文档复制到新集合。

Or create multiple collections based on a weekly/period date, and use as the current one. 或基于每周/期间创建多个集合,并将其用作当前集合。 Then have your application always use the current one by name and change the name at each period break. 然后让您的应用程序始终按名称使用当前名称,并在每个句点更改名称。

This is one of the worst limitations of MongoDB. 这是MongoDB的最严重的限制之一。 we can not rename sharded collection. 我们无法重命名分片集合。 Mongodb Document says: db.collection.renameCollection() is not supported on sharded collections. Mongodb文档说:分片集合不支持db.collection.renameCollection()。

We had the same situation where we created another temporary collection, loaded data into that temporary collection. 在相同的情况下,我们创建了另一个临时集合,然后将数据加载到该临时集合中。 Dropped the existing sharded collection and created new collection with new name and then again loaded back data in newly named collection. 删除现有的分片集合,并使用新名称创建新集合,然后再次将数据加载回新命名的集合中。 This process was very 这个过程非常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM