Reputation: 239
How can I rename a collection in mongodb sharding? 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. 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.
Please suggest what we have to take it further?.
Upvotes: 3
Views: 4097
Reputation: 370
It's now possible to rename Sharded Collections from Mongo 5 or above (assuming same DB for source and target).
It still not possible to rename Time Series collections.
Reference: https://www.mongodb.com/docs/manual/reference/command/renameCollection/
Upvotes: 0
Reputation: 71
This is one of the worst limitations of MongoDB. we can not rename sharded collection. Mongodb Document says: db.collection.renameCollection() is not supported on sharded collections.
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
Upvotes: 1
Reputation: 7590
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.
Upvotes: 2