Error: addShard() command returns error:
{
“ok” : 0,
“errmsg” : “couldn’t connect to new shard socket exception [CONNECT_ERROR] for replname/hostname:27017”
}
Cause:
1. hostname:27017 cannot be reached
2. if hostname:27017 can be reached, then your replica set [replname] configuration contains members with ‘localhost‘ as host name
Solution: Unless you are running all mongod/mongos instances on the same machine, then you can use ‘localhost’ in rs.Add() command. Otherwise, use hostname instead of localhost in all rs.Add(), sh.addShard() command. Note that when adding a host itself to replcaset/shard an usable hostname should be present in /etc/hosts, or you will get this error:
{ “errmsg” : “couldn’t initiate : can’t find self in the replset config”, “ok” : 0 }