Search code examples
mongodbnosqlsharding

Connection refused when adding shard in mongoDB


I followed the Digital Ocean tutorial to create a basic sharded cluster in MongoDB with 1 query router,1 config server and 2 shards without replication on the Virtual box in Ubuntu 16.04. I have successfully established the connection between Query Router and Config server according to the tutorial provided but I am getting the error

   { "ok" : 0, "errmsg" : "Connection refused", "code" : 6 }

when I run sh.addShard("ip:port"). Can someone point what wrong I have been doing? PS: I have bindIP as 0.0.0.0 on all my nodes.


Solution

  • The reason for the error was quite trivial which I figured out by using the tool nmap

        sudo nmap -p 27017 IP_of_the_shard_node
    

    I figured out that the port 27017 was closed to connections.I realised that the mongod service was not running. Therefore a simple

       sudo systemctl start mongod
    

    on shard node would solve the problem.