Why cant I connect to replica set using mongo shell?

Nilesh picture Nilesh · Jan 23, 2017 · Viewed 9.5k times · Source

I can connect to replica set using following command from mongo shell version 3.2.11. But the same does not works with mongo shell v3.4.1.

mongo --host \
      "replicaSet1/10.10.10.15:27001,10.10.10.16:27002,10.10.10.17:27000" mydbname \
      -u root -p root \
      --authenticationDatabase admin

 [main] Error: Failed to parse mongodb:// URL: mongodb://replicaSet1/10.10.10.15:27001,10.10.10.16:27002,10.10.10.17:27000/mydbname :

I have read here that replica set address format has not changed since v 3.4.1 release.

Why cant I connect to db ? What is the parse error, as per new format(if its there).

Answer

Stennie picture Stennie · Jan 23, 2017

This is a known regression in MongoDB 3.4.0/3.4.1: SERVER-27289: mongo --host replSet/Host:Port no longer works. A fix has been committed for the upcoming MongoDB 3.4.2 release.

You can work around this in an affected 3.4.x mongo shell by using the standard MongoDB Connection String URI format instead:

mongo --host mongodb://10.10.10.15:27001,10.10.10.16:27002,10.10.10.17:27000/mydbname?replicaSet=replicaSet1

You can also use a standard MongoDB Connection String as a plain argument (i.e. without the --host parameter):

mongo mongodb://10.10.10.15:27001,10.10.10.16:27002,10.10.10.17:27000/mydbname?replicaSet=replicaSet1

I have read here that replica set address format has not changed since v 3.4.1 release.

Support for using the standard MongoDB Connecting String format in the --host parameter was added in MongoDB 3.4 in order to align the mongo shell connection string syntax with the format used by all official drivers.

This change is currently not noted in the MongoDB 3.4 manual, so I've raised DOCS-9808 to clarify.