Help Center> Document Database Service> User Guide> Troubleshooting> Mongo Shell Fails to Connect to the DB Instance, Leaving Message "No route to host" and "connection attempt failed"

Mongo Shell Fails to Connect to the DB Instance, Leaving Message "No route to host" and "connection attempt failed"

Symptom

An error is reported when you run the following command to connect to a DDS DB instance:

mongo --host 192.168.1.6 --port 8635 -u rwuser -p xxxxxxxxx --authenticationDatabase admin --ssl --sslCAFile /root/ca.crt --sslAllowInvalidHostnames

Error message:

MongoDB shell version v3.4.17
connecting to: mongodb://192.168.1.6:8635/
2019-09-19T09:38:36.954+0800 W NETWORK  [thread1] Failed to connect to 192.168.1.6:8635, in(checking socket for error after poll), reason: No route to host
2019-09-19T09:38:36.954+0800 E QUERY    [thread1] Error: couldn't connect to server 192.168.1.6:8635, connection attempt failed :
connect@src/mongo/shell/mongo.js:240:13
@(connect):1:6
exception: connect failed

Possible Cause

  • The DB instance port is incorrect.
  • The DDS instance and ECS are not in the same region.
  • The DDS DB instance and ECS are not in the same subnet.

For details about how to connect to a DB instance through a private network, see Connecting to a DB Instance Through an ECS.

Solution

You can run the curl command to check whether the network connection to the DDS instance is normal. The following is a command example:

curl 192.168.1.6:8635

If the message "It looks like you are trying to access MongoDB over HTTP on the native driver port." is displayed, the IP address can be connected and port 8635 can be used for communication.

Figure 1 Command output