Unable to connect to mongodb dedicated cluster with auto scaling from go driver

DB String - > mongodb://<user>:<password>@rycaocluster-shard-00-02.apwt4.mongodb.net:27017/

please note that I have MongoDB Atlas Dedicated Server with Auto Scaling and I have used the primary node of the cluster in the string.

Error -
2022/03/17 20:18:18 server selection error: server selection timeout, current topology: { Type: Unknown, Servers: [{ Addr: rycaocluster-shard-00-02.apwt4.mongodb.net:27017, Type: Unknown, Last error: connection() error occured during connection handshake: connection(rycaocluster-shard-00-01.apwt4.mongodb.net:27017[-64]) socket was unexpectedly closed: EOF }, ] }

I searched about this and found a solution -

The solution says to provide a tlsCAfile in the DB String, but I am not sure how to configure a tls certificate in MongoDB Atlas. Please tell me if you know how to do that, or if you have any other solutions.

Hi @VIBHANSHU_RATHOD and welcome in the MongoDB Community :muscle: !

You are supposed to connect to the entire Replica Set, not just the primary. Use the connect button to retrieve the correct connection string starting with mongodb+srv://....

As this actually points to a DNS seedlist, this will redirect your connection to the right servers if your cluster ever scales up or down due to the auto scaling.


1 Like

it doesn’t work, mongodb doesn’t work with the srv link, any solution? also the same MongoDB worked on a vultr server but is not working on an aws ec2 server.

It could be different reasons. Here are the usual one I know about:

  • Forgot to add the IP address of the EC2 server in the IP Access List. That being said, it would be better to use the AWS Peering or even better the AWS Private Link. Both are available in Atlas (M10 and above only because it needs a dedicated env)
  • Root certificated too old. Usually it’s because you are running on an old OS that’s not up-to-date.
  • Forgot to install the DNS dependency that some drivers don’t include by default. For example for python you need to install pymongo[srv] and not just pymongo.

Can you connect from a mongosh from this same EC2 machine? This would be the first thing to check.


1 Like

I am aware about pymongo[srv], what is the similar dependency for go driver?

It doesn’t look that there is one in Go. But I never tried myself. I didn’t notice you where using Go earlier. You should be good to go with just the Go Driver.

Can you connect from mongosh from the same PC you are trying to connect from the Go driver?