I have a Atlas M10 replica cluster with 3 nodes. I can connect to it successfully using the standard “+srv” connection string. However, I now need to connect to each replica node separately using mongosh. (I need to do this so I can run the ‘compact’ command on each node separately)
Is this possible? How do I find the host names of each of the nodes so I can pass it to mongosh connection string? I assume when connecting to direct nodes I should not specify the “+srv” in connection string. So far I have tried to using the “…shard-00-01…” domain names that I see in Atlas UI as the host.
Example I have tried (in Linux): mongosh 'mongodb://<username>:<password>@<...shard-00-01 domain...>/dbname'
As not to repeat myself have a look at the DNS queries in this post to query for the required hosts and connection options.
All atlas connections use TLS. This is implicit when using a mongodb+srv uri but when using a mongodb:// the tls=true option will need to be specified.
mongosh will connect to the replicaset primary when multiple hosts or the replicaSet option is provided. To connect to a specific host exclude the replicaSet option or use the directConnection option.
So taking the TXT parameters, one host from the replicaset, and adding tls and direct connection options: