Not able to connect using Go-MongoDB driver

Hi, Im trying to connect to my remote replica set mongo deployment using go-mongo driver but I’m not able to connect. Im getting the following error while trying to connect.

fatal error server selection error: server selection timeout, current topology: { Type: ReplicaSetNoPrimary, Servers: [{ Addr: 6bfaf4e4-a9a3-4783-8739-7c7f1928500e-0.a618efcd6c3341158fb843970f0d7edd.databases.appdomain.cloud:30870, Type: Unknown, Average RTT: 0, Last error: connection() error occured during connection handshake: connection(6bfaf4e4-a9a3-4783-8739-7c7f1928500e-0.a618efcd6c3341158fb843970f0d7edd.databases.appdomain.cloud:30870[-50]) socket was unexpectedly closed: EOF }, { Addr: 6bfaf4e4-a9a3-4783-8739-7c7f1928500e-1.a618efcd6c3341158fb843970f0d7edd.databases.appdomain.cloud:30870, Type: Unknown, Average RTT: 0, Last error: connection() error occured during connection handshake: connection(6bfaf4e4-a9a3-4783-8739-7c7f1928500e-1.a618efcd6c3341158fb843970f0d7edd.databases.appdomain.cloud:30870[-52]) socket was unexpectedly closed: EOF }, { Addr: 6bfaf4e4-a9a3-4783-8739-7c7f1928500e-2.a618efcd6c3341158fb843970f0d7edd.databases.appdomain.cloud:30870, Type: Unknown, Average RTT: 0, Last error: connection() error occured during connection handshake: connection(6bfaf4e4-a9a3-4783-8739-7c7f1928500e-2.a618efcd6c3341158fb843970f0d7edd.databases.appdomain.cloud:30870[-51]) socket was unexpectedly closed: EOF }, ] }

Im using go version go1.13.4 darwin/amd64, and the mongo instance Im trying to connect is version 4.0.

Please help.
Thanks

Hi Santhosh,

Could you provide some more information about your MongoDB setup? Are you connecting to a MongoDB Atlas cluster or a local MongoDB instance? Is it a standalone or a replica set?

Also, could you provide the connection string you are using to try and connect to MongoDB with (without any credentials of course)

Hi,

Thanks for the response. Im trying to connect to a replica set instance hosted on ibmcloud.
Im able to connect without any error and client.Ping is also working fine, but when Im trying to list database or do any operations on DB from the client I’m getting the following error.

Here is the connection string : mongodb://$USERNAME:$PASSWORD@6bfaf4e4-a9a3-4783-8739-7c7f1928500e-0.a618efcd6c3341158fb843970f0d7edd.databases.appdomain.cloud:30870,6bfaf4e4-a9a3-4783-8739-7c7f1928500e-1.a618efcd6c3341158fb843970f0d7edd.databases.appdomain.cloud:30870,6bfaf4e4-a9a3-4783-8739-7c7f1928500e-2.a618efcd6c3341158fb843970f0d7edd.databases.appdomain.cloud:30870/ibmclouddb?authSource=admin&replicaSet=replset.

Also Im able to connect to this instance via shell and mongodb compass.
Thanks.

This issue can be closed, I found the solution to the issue im facing. I had to provide the tls cert/pem file in the connection string URI with the parameter tlsCAfile=filename.pem.

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.