On Cloud Mongo (Mongo Atlas) Free tier, it has 3 members of servers. How can I connect to the Secondary host from Mongo shell? Their example only shows how to connect to Primary.
"members" : [
{
"_id" : 0,
"name" : "***-shard-00-00-***.mongodb.net:27017",
....
},
{
"_id" : 1,
"name" : "***-shard-00-01-***.mongodb.net:27017",
.....
},
{
"_id" : 2,
"name" : "***-shard-00-02-***.mongodb.net:27017",
.....
}
]
You need to use the --ssl flag and specify authSource.
Try:
mongo "mongodb://***-shard-00-02-***.mongodb.net:27017/?authSource=admin" --ssl
at the very minimum. Of course you can add options for username, password, database to connect, etc...
mongo "mongodb://<username>:<password>@***-shard-00-02-***.mongodb.net:27017/<database>?authSource=admin" --ssl
I hope this helps.
Another way to connect to secondary through mongosh
Here are the steps:
Retrieve the hostname from the Atlas cluster by clicking View Monitoring on the cluster
Copy the secondary node hostname without the port number. For example: clustername-shard-00-01.abcde.mongodb.net
To connect to the node, run the following mongosh command from the command line, replacing <secondary hostname> with the secondary hostname you copied in the previous step, and replacing <database user> with the database user created for the project:
mongosh "mongodb://<secondary hostname>/myFirstDatabase" --tls --authenticationDatabase admin --username <database user>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With