0

After converting the standalone to the replica set the connection string has not been modified, but it works fine.

If I type mongo <server IP> the connection string is still the same as it was before the conversion mongodb://mongodb0.example.com:27017/admin?compressors=disabled&gssapiServiceName=mongodb.

How to convert it into mongodb://mongodb0.example.com:27017,mongodb1.example.com:27017,mongodb2.example.com:27017/admin?replicaSet=myRepl&readPreference=primaryPreferred?

I have tried to set read preferences with db.getMongo().setReadPref('primaryPreferred'), but the string is still the same.

Thanks!

hc_dev
  • 8,389
  • 1
  • 26
  • 38
eceyou
  • 23
  • 1
  • 4
  • I understood that you want to use **mongo CLI** `mongo` to connect to a replica-set using read-preference? Which of the strings worked as command-line argument? – hc_dev Nov 24 '19 at 16:37

1 Answers1

0

Try your connection string without admin (or even without the standard port :27017). Then it's pretty much the same like in the Doc's for connection string with read-preference:

mongodb://db0.example.com,db1.example.com,db2.example.com/?replicaSet=myRepl&readPreference=secondary&maxStalenessSeconds=120

Passing it as argument within double-quotes to the mongo shell (see the CLI syntax)you could type like following on the command-line (terminal):

mongo "mongodb://mongodb0.example.com.local:27017,mongodb1.example.com.local:27017,mongodb2.example.com.local:27017/?replicaSet=replA"
hc_dev
  • 8,389
  • 1
  • 26
  • 38