Consider the following guidelines when formatting your connection string to connect to a MongoDB instance.

  • The query parameter tls= is not supported. Use ssl= to achieve the same degree of security.
  • Use uppercase when URL escaping characters. For example, %2F.
  • Consider using MongoDB Compass to connect to your replica set to help construct a valid connection string and verify the configuration.
  • Use the mongodb+srv:// URI format to avoid having to create new connection strings if the servers in the replica set change.

Example Connection String

mongodb://myusername:<password>@
ec2-123-123-12.compute-1.amazonaws.com27017,
ec2-234-234-23.compute-1.amazonaws.com:27017,
ec2-456-456-45.compute-1.amazonaws.com:27017/
?authSource=admin
&replicaSet=rs0
&readPreference=primary
&ssl=true