Connecting string for M2

Hello,
What is the connecting string Atlas M2 cluster
I’m using the following, Is it OK?

mongodb+srv://<username>:<password>@
cluster0.XXXXX.mongodb.net,
cluster0-shard-00-00.XXXXX.mongodb.net:27017,
cluster0-shard-00-01.XXXXX.mongodb.net:27017,
cluster0-shard-00-02.XXXXX.mongodb.net:27017
/YYYYY?ssl=true&replicaSet=atlas-razveo-shard-0&authSource=admin&retryWrites=true&w=majority

Sometimes have the following exceptions-
1.
SocketException: Software caused connection abort (OS Error: Software caused connection abort, errno = 103), address = cluster0-shard-00-02.XXXXX.mongodb.net, port = 42848

 ConnectionException: connection closed: The socket connection has been reset by peer.
Possible causes:
- Trying to connect to an ssl/tls encrypted database without specifiyng
  either the query parm tls=true or the secure=true parameter in db.open()
- The server requires a key certificate from the client, but no certificate has been sent
- Others

The conect string is not as per SRV format
You can get it from your Atlas account
It should not have individual hostnames and replicaset name.Looks like you mixed both SRV & long form of strings

Thanks
When I use the recommended string from atlas I have exception

The string -
"mongodb+srv://<username>:<password>@cluster0.XXXXX.mongodb.net/YYYYY?retryWrites=true&w=majority";

The exception -
MongoDB ConnectionException: Could not connect to cluster0.YYYYY.mongodb.net:27017
SocketException: Failed host lookup: ‘cluster0.YYYYY.mongodb.net’ (OS Error: No address associated with hostname, errno = 7)

A few things.

I am surprised that you get the error No address associated with hostname as this error would indicate that you are missing +srv in your connection string. A cluster has no host name address it has a seed list record which is different and generates a different error message.

Hiding your real cluster name does not help us helping you.

Hiding your cluster name relies on security through obscurity. Appropriate network setup and user access is a better way.

Thanks,
Here is the connection string
const uri = “mongodb+srv://:@cluster0.lyltx.mongodb.net/myFirstDatabase?retryWrites=true&w=majority”;
Kobi

The cluster DNS is correct as seen below.

id 23124
opcode QUERY
rcode NOERROR
flags QR RD RA
;QUESTION
cluster0.lyltx.mongodb.net. IN ANY
;ANSWER
cluster0.lyltx.mongodb.net. 60 IN TXT "authSource=admin&replicaSet=atlas-7g2b5k-shard-0"
;AUTHORITY
;ADDITIONAL

There are however some inconsistencies with what you posted earlier.

You specified

but the real replica set name is atlas-7g2b5k-shard-0. How did you get the razveo name?

Basically, the following should work with the appropriate user name and password.

If it still does not work, verify that

  1. you allow connections from your public IP in network security
  2. that your firewall, isp or vpn allows outgoing connection via port 27017

Thanks
I just updated the replica as your suggestion in my long format . and its working
The short format didn’t work
Is it possible that I need to add parameters for the cluster?
Now I will see if have more exceptions

1 Like