Hello All,
I am writing a module to check if mongod/mongos is running on a give host-port combination. I am making use of the ping command with mongoc driver to achieve this.
My mongos server is bound to the IP of the machine and not the hostname. Lets say the IP is 192.168.1.6 and hostname is myHost. In /etc/hosts, I have 192.168.1.6 myHost. mongos is running on port 27020.
For me, the following command from shell gives a connection error. This is expected as my mongos is not bound to myHost. It is bound to 192.168.1.6.
============================================================================
>mongo --port 27020 --host myHost --eval “db.adminCommand({ping: 1})”
MongoDB shell version: 3.2.22
connecting to: myHost:27020/test
2020-03-31T16:37:19.598+0530 W NETWORK [thread1] Failed to connect to 127.0.0.1:27020, in(checking socket for error after poll), reason: errno:111 Connection refused
2020-03-31T16:37:19.598+0530 E QUERY [thread1] Error: couldn’t connect to server centostemp:27020, connection attempt failed :
connect@src/mongo/shell/mongo.js:231:14
@(connect):1:6
exception: connect failed
============================================================================
But, when running the ping command using mongoc driver with host as myHost and port as 27020. It successfully connects which I don’t expect to happen. As a result, my connectivity check module is giving false positives.
I suspect there is a dns lookup happening when running the command using mongoc driver. Is there anyway to stop this from happening?
Thanks,
Santhanu