Unfortunately there is some stuff that will not be cleaned up through dropDatabase. On the other hand if you delete it by hand may not will be harmful. Some data like statistics will reside on your nodes anyway till the restart of mongods. (Try it out first! Not on the production), as the configuration database is relatively small and does not have huge requirements in terms of performance, that maybe even not a problem, just to be on the safe side and leave them as they are.
Also something to check out how to make the manual actions:
https://stackoverflow.com/questions/9407838/mongodb-dropdatabase-not-working
and as it is mentioned on this question the dropDatabase in such case a bit bugy:https://jira.mongodb.org/browse/SERVER-4804
New to MongoDB, but this is how I learned how to do the same thing following the MongoDB 202 class. There are other ways to balance traffic, such as moving, splitting and merging chunks. I haven't read anywhere that directly updating the tags collection in the config database was dirty or incorrect.
The code below is untested, and you will have to replace certain values like nameofShard and the minimum, maximum values. You will notice that I stop the balancer before modifying the tag ranges
// stop the balancer
sh.stopBalancer()
// remove the tags from the shards
sh.removeShardTag("nameofshardN", "rangeTime1")
sh.removeShardTag("nameofshardN+1", "rangeTime2")
// remove the existing tags
db.tags.remove({ "_id" : { "ns" : "testlab.range", "min" : { "_id" : 1 } }, "ns" : "testlab.range", "min" : { "_id" : 1 }, "max" : { "_id" : 100 }, "tag" : "rangeTime1" })
db.tags.remove({ "_id" : { "ns" : "testlab.range", "min" : { "_id" : 100 } }, "ns" : "testlab.range", "min" : { "_id" : 100 }, "max" : { "_id" : 200 }, "tag" : "rangeTime2" })
// Add new tags
sh.addTagRange("testlab.range", {_id : new_minimum_value}, {_id : new_maximum_value}, "rangeTime1");
sh.addTagRange("testlab.range", {_id : new_minimum_value}, {_id : new_maximum_value}, "rangeTime2");
// Add shardTag
sh.addShardTag("nameofshardN", "rangeTime1")
sh.addShardTag("nameofshardN+1", "RangeTime2")
// start balancer
sh.startBalancer()
sh.status() or mongostat --port 27017 --discover
to verify balancing
test.lab is not a valid database name, so I changed my database name to testlab.
One additional remark about the _id field not being updated. When I query the tags collection like so
mongos> db.tags.find({}, {_id:1})
{ "_id" : { "ns" : "testlab.range", "min" : { "_id" : 1 } } }
{ "_id" : { "ns" : "testlab.range", "min" : { "_id" : 100 } } }
It shows that the _id field contains the min value or the tag range. If you are updating the tags collection and modifying the tags min field value, then wouldn't it also be reasonable to update the _id field's min value as well?
Best Answer
Try
db.repairDatabase()
which fixes inconsistency across database. Checkmongod
andmongos
logs for results.