-1

I cannot find a solution for my question so I have to ask. I've made a mongodb cluster in Atlas. Now via shell I want to connect primary replicaset node. Could you please help me?

After connecting my cluster via shell I see this:
MongoDB Enterprise AkademiaWSB-shard-0:PRIMARY>

Meaby it is primary node but how to switch between nodes? screen of my replica set

3 Answers3

1

You need to connect the instance with URI format.

The below example uses 3.6. It will be the same for higher versions too.

https://docs.mongodb.com/v3.6/reference/connection-string/

Please refer the above connection string format.

A replica set without authentication enforced.

mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/admin?replicaSet=myRepl

A replica set with authentication enforced

mongodb://myDBReader:D1fficultP%40ssw0rd@mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/admin?replicaSet=myRepl

0

The shell shows you correctly that you are connected to Primary.

Why do you need to connect to other nodes? You should read/write from primary (as a basic principle).

Yahya
  • 3,386
  • 3
  • 22
  • 40
0

If your replica-set members are host on a remote you can connect the other mongo's shell used:

mongo --host mongodb0.example.com:27018

Also if you want to locate your replica-set Primary server you just need to connect to one of your replicas shell and run rs.stats(). Then connect to the primary node used the command above.

Good Luck! ;)

genericUser
  • 4,417
  • 1
  • 28
  • 73