Reputation: 8940
I have created a collection on mongodb that is sharded on the wrong key. I want to drop my collection and rebuild it so that it is sharded on the right key.
Unfortunately doing db.removeCollection('mycollection') removes the data but not some metadata info.
db.printShardingStatus still shows the sharding info I wrongly used for mycollection, and if I create the collection again I can't shard it with the new good key because it says "already sharded".
Any solution ?
Thanks
Thomas
Upvotes: 5
Views: 11920
Reputation: 891
If you check out this JIRA ticket, there's a very detailed discussion of how to safely unshard (and re-shard, using a different key) collections in mongoDB: https://jira.mongodb.org/browse/SERVER-9845
The method described in that ticket involves migrating your data to a single shard, removing the metadata, and then re-sharding. If you'd rather drop the data entirely, then rebuild, you should be able to skip the migration step. You will still have to re-start your mongos and shard servers for the change to go into effect.
Upvotes: 6