Connecting to Atlas with pymongo v4.0.2

Hi @Muralidhar_Rao,

Welcome to the community.

Notice the extra “pri”??

The extra “pri” noted in your URI is associated with the private IP addresses of the Atlas nodes of that cluster which should be reachable within the peered network.

For demonstration purposes, using the two URI’s provided, you will see that that the hostnames resolved from the SRV record differ slightly with the additional “pri”:

/// Using dig to resolve the "pri" SRV record:
dig srv _mongodb._tcp.cdf46a6c-6797-40e1-a655-pri.35m0c.mongodb.net

/// The answer section which includes the hostnames associated with the Private IP of the nodes within the cluster. Note the additional "pri" in these as well
;; ANSWER SECTION:
_mongodb._tcp.cdf46a6c-6797-40e1-a655-pri.35m0c.mongodb.net. 60	IN SRV 0 0 27017 cdf46a6c-6797-40e1-a655-shard-00-00-pri.35m0c.mongodb.net.
_mongodb._tcp.cdf46a6c-6797-40e1-a655-pri.35m0c.mongodb.net. 60	IN SRV 0 0 27017 cdf46a6c-6797-40e1-a655-shard-00-01-pri.35m0c.mongodb.net.
_mongodb._tcp.cdf46a6c-6797-40e1-a655-pri.35m0c.mongodb.net. 60	IN SRV 0 0 27017 cdf46a6c-6797-40e1-a655-shard-00-02-pri.35m0c.mongodb.net.
/// Using dig to resolve the non-"pri" SRV record:
dig srv _mongodb._tcp.cdf46a6c-6797-40e1-a655.35m0c.mongodb.net

/// The answer section which includes hostnames associated with the public IP of the nodes within the cluster. Note, there is no "pri" in these hostnames.
;; ANSWER SECTION:
_mongodb._tcp.cdf46a6c-6797-40e1-a655.35m0c.mongodb.net. 60 IN SRV 0 0 27017 cdf46a6c-6797-40e1-a655-shard-00-00.35m0c.mongodb.net.
_mongodb._tcp.cdf46a6c-6797-40e1-a655.35m0c.mongodb.net. 60 IN SRV 0 0 27017 cdf46a6c-6797-40e1-a655-shard-00-01.35m0c.mongodb.net.
_mongodb._tcp.cdf46a6c-6797-40e1-a655.35m0c.mongodb.net. 60 IN SRV 0 0 27017 cdf46a6c-6797-40e1-a655-shard-00-02.35m0c.mongodb.net.

You can read more information regarding the above here on the FAQ: Connection String Options documentation.

Ping doesn’t work for either of the hostnames, see below:

From the above dig results, the ping command and output did not succeed as you have attempted to ping the SRV record and not the hostnames. In the below ping example, the hostnames used were obtained from the dig outputs above.

From the python client that is failing to connect, please run the following commands and provide the output of each:

ping cdf46a6c-6797-40e1-a655-shard-00-00-pri.35m0c.mongodb.net
ping cdf46a6c-6797-40e1-a655-shard-00-00.35m0c.mongodb.net

I am not sure what has changed. I am pretty sure I got both connection URLs from Atlas, so is Atlas somehow giving me the wrong URL?

This is also detailed in the FAQ: Connection String Options documentation mentioned above, but the two strings you’ve obtained are from either of the following options when going through the connect modal:

  1. Which is the right host to connect to, the one with pri or the one without?

Generally, if you’re wanting to connect over the VPC peering connection, you should use the Private IP for Peering connection string. Otherwise, if you’re wanting to connect over the public internet to that specific cluster, you can use the standard connection string.

  1. Why can Java driver connect to the host with ‘pri’ in it but Python driver cannot?

Is the client performing this connection using the Java driver the same client as the one attempting connection using the python driver?

Regards,
Jason

3 Likes