The mongo shell accepts mongodb:// URI-style connection strings as a plain argument:
$ /m/3.2.1/bin/mongo mongodb://genique:11111/test?replicaSet=replset MongoDB shell version: 3.2.1 connecting to: mongodb://genique:11111/test?replicaSet=replset 2016-01-30T00:55:35.554+1100 I NETWORK [thread1] Starting new replica set monitor for replset/genique:11111 2016-01-30T00:55:35.554+1100 I NETWORK [ReplicaSetMonitorWatcher] starting 2016-01-30T00:55:35.555+1100 I NETWORK [thread1] changing hosts to replset/genique:11111,genique:11112 from replset/genique:11111 > bye
However, this format currently does not work if passed as the argument to the --host option:
$ /m/3.2.1/bin/mongo --host mongodb://genique:11111/test?replicaSet=replset MongoDB shell version: 3.2.1 connecting to: mongodb://genique:11111/test?replicaSet=replset/test 2016-01-30T00:55:40.327+1100 I NETWORK [thread1] Starting new replica set monitor for replset/test/genique:11111 2016-01-30T00:55:40.327+1100 I NETWORK [ReplicaSetMonitorWatcher] starting 2016-01-30T00:55:40.328+1100 W NETWORK [thread1] node: genique:11111 isn't a part of set: replset/test ismaster: { hosts: [ "genique:11111", "genique:11112" ], arbiters: [ "genique:11113" ], setName: "replset", setVersion: 1, ismaster: true, secondary: false, primary: "genique:11111", me: "genique:11111", electionId: ObjectId('56ab6ab10000000000000005'), maxBsonObjectSize: 16777216, maxMessageSizeBytes: 48000000, maxWriteBatchSize: 1000, localTime: new Date(1454075740328), maxWireVersion: 4, minWireVersion: 0, ok: 1.0 } 2016-01-30T00:55:40.328+1100 W NETWORK [thread1] No primary detected for set replset/test 2016-01-30T00:55:40.328+1100 I NETWORK [thread1] All nodes for set replset/test are down. This has happened for 1 checks in a row. Polling will stop after 29 more failed checks 2016-01-30T00:55:40.829+1100 W NETWORK [thread1] node: genique:11111 isn't a part of set: replset/test ismaster: { hosts: [ "genique:11111", "genique:11112" ], arbiters: [ "genique:11113" ], setName: "replset", setVersion: 1, ismaster: true, secondary: false, primary: "genique:11111", me: "genique:11111", electionId: ObjectId('56ab6ab10000000000000005'), maxBsonObjectSize: 16777216, maxMessageSizeBytes: 48000000, maxWriteBatchSize: 1000, localTime: new Date(1454075740829), maxWireVersion: 4, minWireVersion: 0, ok: 1.0 } 2016-01-30T00:55:40.829+1100 W NETWORK [thread1] No primary detected for set replset/test 2016-01-30T00:55:40.829+1100 I NETWORK [thread1] All nodes for set replset/test are down. This has happened for 2 checks in a row. Polling will stop after 28 more failed checks 2016-01-30T00:55:41.329+1100 W NETWORK [thread1] node: genique:11111 isn't a part of set: replset/test ismaster: { hosts: [ "genique:11111", "genique:11112" ], arbiters: [ "genique:11113" ], setName: "replset", setVersion: 1, ismaster: true, secondary: false, primary: "genique:11111", me: "genique:11111", electionId: ObjectId('56ab6ab10000000000000005'), maxBsonObjectSize: 16777216, maxMessageSizeBytes: 48000000, maxWriteBatchSize: 1000, localTime: new Date(1454075741329), maxWireVersion: 4, minWireVersion: 0, ok: 1.0 } 2016-01-30T00:55:41.329+1100 W NETWORK [thread1] No primary detected for set replset/test 2016-01-30T00:55:41.329+1100 I NETWORK [thread1] All nodes for set replset/test are down. This has happened for 3 checks in a row. Polling will stop after 27 more failed checks ^C
But --host accepts all other valid connection specifications, ie:
- mongo --host hostname
- mongo --host hostname:port
- mongo --host replsetname/seedhostname1:port,seedhostname2:port,...
- mongo --host /tmp/mongodb-XXXXX.sock
Therefore, it's reasonable to expect that
- mongo --host mongodb://...
should also work, with the same behaviour as when --host is not used.
The problem appears to be that the dbname specified by a plain argument (which defaults to "test") gets appended to the --host argument (as well as a slash). For the traditional forms of --host (listed above), this makes sense because they can't specify the dbname. So appending the dbname to --host gives the corresponding plain argument, eg. "mongo --host hostname:port dbname" is equivalent to "mongo hostname:port/dbname". But this doesn't make sense for the URI format, because it has its own way of specifying the dbname. So a simple fix should be to avoid appending "/dbname" if the argument to --host starts with "mongodb://".
- is depended on by
-
SERVER-30850 startParallelShell cannot be used in a shell started with a replica set connection string
- Closed
- is related to
-
SERVER-33227 Using the method `connect` in a script will as a side effect update global `db`.
- Closed
-
SERVER-27289 Shell: mongo --host replSet/Host:Port no longer works
- Closed
- related to
-
SERVER-6233 Support MongoDB URIs as mongo shell argument
- Closed