[DOCS-8934] mongo shell should accept mongodb:// URI for --host Created: 28/Sep/16  Updated: 30/Oct/23  Resolved: 21/Jan/18

Status: Closed
Project: Documentation
Component/s: Server
Affects Version/s: None
Fix Version/s: Server_Docs_20231030

Type: Task Priority: Major - P3
Reporter: Emily Hall Assignee: Unassigned
Resolution: Duplicate Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Documented
documents SERVER-22382 mongo shell should accept mongodb:// ... Closed
Participants:
Days since reply: 6 years, 3 weeks, 4 days ago

 Description   

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://".



 Comments   
Comment by Kay Kim (Inactive) [ 21/Jan/18 ]

DOCS-9033

Generated at Thu Feb 08 07:57:15 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.