MongoDB error can’t add shard because a local database ‘test’ exists in another shard

Error: When add shard with sh.addShard(), if new shard contains a DB with the same name as in previously added shards, MongoDB can’t automatically merge them:

errmsg” : “can’t add shard server2:27017 because a local database ‘test’ exists in another shard000:server1:27017

Solutions: mongodump the data on new shard, then drop that database and addShard. After that you can import the dump data using mongorestore

MongoDB error can’t add shard because a local database ‘test’ exists in another shard