Following the MongoDB Sharding Documentation, I start a mongos using a configuration file with the specifics of my config server.

It seems rather straightforward, yet I am running into an issue. I start mongos on one machine (lets say its ip address is "some_ip"):

$ sudo mongos --config /etc/some_config.conf

And I try connecting to its shell from another machine, but I get connection refused error.

$ mongos some_ip:xxxxx

Here's part of my some_config.conf file:

      port: xxxxx

      configDB: <configReplSet>/<ip_of_config>:27019

I'm using for testing purposes. I made sure that the ip_addr and port I'm connecting to matches the ip of the host for the mongos and the port I specified in the net.port param. I also opened up this port in my firewall for ingress/ egress connections.

Did I miss anything ? (NOTE: ** I edited post for further clarification)


(note: i replaced the actual ip addr with "ip_of_config") This is what my log file for my mongos says when I start mongos.

2018-05-02T05:57:48.533+0000 W NETWORK  [monitoring keys for HMAC] Failed to 
connect to <ip_of_config>:27019, in(checking socket for error after poll), reason: 
Connection refused
2018-05-02T05:57:48.533+0000 W NETWORK  [monitoring keys for HMAC] Unable to 
reach primary for set crs0

Now my config server is up and running fine, but its log file shows that it accepts multiple connections from my mongos server, but these connections close almost immediately. Also there are a few warning logs:

W SHARDING [Balancer] Balancer settings could not be loaded and will be 
retried in 10 seconds :: caused by :: ReadConcernMajorityNotAvailableYet: 
Failed to refresh the balancer settings due to 
ReadConcernMajorityNotAvailableYet: Read concern majority reads are currently 
not possible.

W SHARDING [shard registry reload] cant reload ShardRegistry  :: caused by :: 
CallbackCanceled: Callback canceled
  • ,Welcome to the site. what are you trying to connect with mongos. If you are trying to connect replica set. How many replica set is there. Suppose that if you trying to connect 3 replica set with mongos, then how you are configure the "config" sharding field in "mongos.conf" file. Did you bindIP & with specific port number to mongos or not. – Md Haidar Ali Khan May 2 '18 at 11:12
  • what is MongoDB version(x,y,z)? – Md Haidar Ali Khan May 2 '18 at 11:15
  • MongoDB version is v3.6.4. I have already set up mongos with the config server (I'm using one for testing) and set up the bindIp and port in conf file for the mongos. That's not the issue I have. The issue I have is that I am running mongos given a config file I created on one machine, and on another machine I'm trying to connect to mongos so I can add shards to the cluster. Yet when I try to connect to mongos given that machine's ip and port (as specified on the mongos conf file), I get connection refused. – rapidDev May 3 '18 at 1:45
  • The concern is that what you are using in "mongos.conf" bindIP & port number. The IP address which you are using in "mongos.conf" and what you are using in replica set node. – Md Haidar Ali Khan May 3 '18 at 5:11

You didn't tell your mongodb version, but I guess that you are using one of the newest, so you need to set net.bindIp too, because it's default value is localhost and as you know, you cannot connect localhost from outside of machine.

  • The MongoDB version is v3.6.4. I did set the net.bindIp to to allow for any connections (just for testing purposes). I just revised the post to further clarify my setup. Hopefully that would give you a better idea of my issue. – rapidDev May 3 '18 at 2:43
  • You start mongos and after that you use mongo --host <address> --port <port> to connect it.. You don't use mongos to connect mongos.. ;-) – JJussi May 3 '18 at 10:40
  • Getting into the hang of checking the logs and understanding them much more. It seems that my mongos server has trouble connecting to my config server. The config server is receiving connections from the mongos but they close almost immediately. Further explanation in the post I just updated. – rapidDev May 3 '18 at 17:11

mongos for “MongoDB Shard,” is a routing service for MongoDB shard configurations that processes queries from the application layer, and determines the location of this data in the sharded cluster, in order to complete these operations. From the perspective of the application, a mongos instance behaves identically to any other MongoDB instance.

As you have mention here mongos.conf file

      port: xxxxx

      configDB: <configReplSet>/<ip_of_config>:27019

As here i would like to say that here as you are bindIp in mongos.conf file with but in sharding section , you are using with port number 27019 of any replica set.

Note : As here I am not able to see any logpath destion in your mongos.conf file.

As per MongoDB BOL documentation here Starting in MongoDB 3.6, mongos bind to localhost ( by default.

Did you try with this configuration of your mongos.conf file.

  configDB: replicasetname/ipaddress:27019 -- external ip of replica set of any node which port is 27019, as you mention in your code. which must be participate the replication. 
  bindIp: localhost,ipaddress -- external ip address, if you are using  
  port: xxxxx --port number of mongos, it should be different from replica set node port number
  destination: file
  path: -- log destination of mongos file
  logAppend: true
  fork: true             -- if you are using the fork

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.