phpmongodbmongoosesharding

MongoDB Rename collection in Sharding


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?.


Solution

  • 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.