What is the best connection string from SRV or Replica Set for MongoDB connection?

I’m confused about MongoDB connection strings from SRV and Replica Set,

I have running Replica Set, and when i open the connection option by clicking on connect button, i can not see Replica Set connection string example or any kind of recommendation,

But i can see the Replica Set connection string example in 2.2.12 or later option.

If Replica Set connection string is good then why we are showing or recommending connection options for the latest versions in the model?

What is the best way to connect MongoDB to my application, I am using MongoDB 4.4 version.

Thank you.

SRV records are a somewhat recent addition to the DNS protocol. See SRV record - Wikipedia.

It is not supported in old version of MongoDB. If you use a version that supports it, it is recommended that you use it as it simplifies thing on the client side. For example, if you add, remove or move a replica set member with the old non SRV style, you need to modify the connection string. With SRV you do not, because this information is retrieved by DNS queries.

For example with your cluster sandbox.3xqto.mongodb.net with Dig (DNS lookup) we can find the replica set name and by querying the TXT record. Which will provide the following answer:


The query for the SRV record is tricky since you have to prefix the cluster name with _mongodb._tcp and you will get:

_mongodb._tcp.sandbox.3xqto.mongodb.net. 59 IN SRV 0 0 27017 sandbox-shard-00-00.3xqto.mongodb.net.
_mongodb._tcp.sandbox.3xqto.mongodb.net. 59 IN SRV 0 0 27017 sandbox-shard-00-01.3xqto.mongodb.net.
_mongodb._tcp.sandbox.3xqto.mongodb.net. 59 IN SRV 0 0 27017 sandbox-shard-00-02.3xqto.mongodb.net.

Thank you @steevej, for the detailed explanation, I understood.

I missed this MongoDB documentation, and also a blog MongoDB 3.6: Here to SRV you with easier replica set connections

Thanks for the extra links.

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