[SERVER-27289] Shell: mongo --host replSet/Host:Port no longer works Created: 05/Dec/16  Updated: 26/May/17  Resolved: 13/Dec/16

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 3.4.0
Fix Version/s: 3.4.2, 3.5.1

Type: Bug Priority: Minor - P4
Reporter: Vick Mena (Inactive) Assignee: Matt Cotter
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Backports
Documented
is documented by DOCS-9808 mongo --host doesn't mention new supp... Closed
Duplicate
is duplicated by SERVER-27731 MongoDB 3.4.1 shell still unable to c... Closed
is duplicated by SERVER-27404 Mongo shell `--host` option for repli... Closed
is duplicated by SERVER-27417 Failed to parse host option if replic... Closed
Related
related to SERVER-22382 mongo shell should accept mongodb:// ... Closed
is related to SERVER-28072 Running a script using 'mongo' on rep... Closed
Backwards Compatibility: Fully Compatible
Operating System: ALL
Backport Requested:
v3.4
Steps To Reproduce:
  1. Create a replica set
  2. Connect from the shell using the the --host parameter: mongo --host replSet/Host:Port
Sprint: Platforms 2017-01-23
Participants:
Case:

 Description   

In v3.4 the following no longer works

mongo --host replset/localhost:27018
MongoDB shell version v3.4.0
connecting to: mongodb://replset/localhost:27018
2016-12-05T21:45:22.474+0000 E QUERY    [main] Error: Failed to parse mongodb:// URL: mongodb://replset/localhost:27018 :
connect@src/mongo/shell/mongo.js:234:13
@(connect):1:6
exception: connect failed

Where it used to work in v3.2

usr/local/m/versions/3.2.10/bin$ ./mongo --host replset/localhost:27018
MongoDB shell version: 3.2.10
connecting to: replset/localhost:27018/test

The documentation has an example.



 Comments   
Comment by James Lucas [ 15/Mar/17 ]

This also appears to break running javascript files from the command line, since you have to specify them after the target database name.

Comment by Mark Agarunov [ 15/Mar/17 ]

Hello jlucas,

Thank you for reporting this behavior. This appears to be an instance of the issue described in SERVER-28072 and we are investigating further. If you would like updates on this issue, please watch the progress in SERVER-28072.

Thanks,
Mark

Comment by James Lucas [ 15/Mar/17 ]

Just wanted to report that I'm still seeing this issue in 3.4.2 on Linux, when trying to specify a default database (which is needed for user authentication from the command line). This is regardless of whether I include a port specification or not.

mongo --host 'rs0/mongotest1,mongotest2' admin
MongoDB shell version v3.4.2
connecting to: mongodb://rs0/mongotest1,mongotest2:27017/admin
2017-03-15T16:15:36.811-0500 E QUERY [thread1] Error: Failed to parse mongodb:// URL: mongodb://rs0/mongotest1,mongotest2:27017/admin :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed

Specifying the full url in the --host string does work.

mongo --host 'mongodb://mongotest1,mongotest2/admin?replicaSet=rs0'
MongoDB shell version v3.4.2
connecting to: mongodb://mongotest1,mongotest2/admin?replicaSet=rs0
2017-03-15T16:18:51.265-0500 I NETWORK [thread1] Starting new replica set monitor for rs0/mongotest1:27017,mongotest2:27017
MongoDB server version: 3.4.2

This change from previous behavior seems to have great potential to break scripts or jobs people may have created under older versions. The manpage also specified the rsname/host1,host2 format.

Comment by Jonathan Reams [ 03/Feb/17 ]

Ah, the format for replica sets in URIs is not quite the same as the old connection string format. If you want to connect to a replica set with a URI you should do mongodb://host1:port,host2:port,host3:port/databasename?replicaSet=replicaSetName. You can read more about it here https://docs.mongodb.com/manual/reference/connection-string/. Let me know if you have any more questions or problems, I want to make sure this is fixed!

Comment by Nick Larson [ 03/Feb/17 ]

Ahh taking a look it appears it IS partially fixed. However it still seems to be breaking when specifying a port as an additional argument.

root@uc-dev $ mongo --version
MongoDB shell version v3.4.2
git version: 3f76e40c105fc223b3e5aac3e20dcd026b83b38b
OpenSSL version: OpenSSL 1.0.1t  3 May 2016
allocator: tcmalloc
modules: none
build environment:
    distmod: debian81
    distarch: x86_64
    target_arch: x86_64
root@uc-dev $ mongo --host RS-Dev-0/localhost --port 27017
MongoDB shell version v3.4.2
connecting to: mongodb://RS-Dev-0/localhost:27017/
2017-02-02T18:45:08.380-0800 E QUERY    [thread1] Error: Failed to parse mongodb:// URL: mongodb://RS-Dev-0/localhost:27017/ :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed

If I include port as part of the host, it works fine. Maybe has something to do with '--port' adding the trailing slash at the end? If I manually add the trailing slash it breaks as well.

root@uc-dev $ mongo --host RS-Dev-0/localhost:27107
MongoDB shell version v3.4.2
connecting to: mongodb://localhost:27107/?replicaSet=RS-Dev-0
2017-02-02T18:51:08.608-0800 I NETWORK  [thread1] Starting new replica set monitor for RS-Dev-0/localhost:27107
2017-02-02T18:51:08.609-0800 W NETWORK  [thread1] Failed to connect to 127.0.0.1:27107, in(checking socket for error after poll), reason: Connection refused
2017-02-02T18:51:08.609-0800 W NETWORK  [thread1] No primary detected for set RS-Dev-0
2017-02-02T18:51:08.609-0800 I NETWORK  [thread1] All nodes for set RS-Dev-0 are down. This has happened for 1 checks in a row.

Edit: disregard my broken replica set.

Edit2: More info. Looks like it breaks when specifying a default database as well (again, maybe do to the trailing slash after port?? wild guess)

root@uc-dev $ mongo --host RS-Dev-0/localhost database
MongoDB shell version v3.4.2
connecting to: mongodb://RS-Dev-0/localhost:27017/database
2017-02-02T18:55:40.047-0800 E QUERY    [thread1] Error: Failed to parse mongodb:// URL: mongodb://RS-Dev-0/localhost:27017/database :
connect@src/mongo/shell/mongo.js:237:13
@(connect):1:6
exception: connect failed

Comment by Daniel Pasette (Inactive) [ 03/Feb/17 ]

Hi Nick,
It's working for me on 3.4.2 on ubuntu. Can you include the output from your session?

dan:dist$ mongodb-linux-x86_64-ubuntu1404-3.4.2/bin/mongo --host name/dan:20000
MongoDB shell version v3.4.2
connecting to: mongodb://dan:20000/?replicaSet=name
2017-02-02T21:42:42.199-0500 I NETWORK  [thread1] Starting new replica set monitor for name/dan:20000
2017-02-02T21:42:42.200-0500 I NETWORK  [thread1] changing hosts to name/dan:20000,dan:20001 from name/dan:20000

Comment by Nick Larson [ 03/Feb/17 ]

FYI still not working for me on 3.4.2

Comment by Ramon Fernandez Marina [ 18/Jan/17 ]

ankon, the fix for this bug was backported to the v3.4 branch earlier today and will be part of the upcoming 3.4.2 release in a few weeks.

Regards,
Ramón.

Comment by Githook User [ 18/Jan/17 ]

Author:

{u'username': u'Machyne', u'name': u'Matt Cotter', u'email': u'matt.cotter@mongodb.com'}

Message: SERVER-27289 fix ConnectionString parsing in shell

(cherry picked from commit 68c8715feaa2ead6a3c25eb9aa512de779c4795d)
Branch: v3.4
https://github.com/mongodb/mongo/commit/316a719cf7e88a3195f94a26a8085e7145660c47

Comment by Andreas Kohn [ 14/Dec/16 ]

As this fixes a 3.4 regression, are there plans to backport this to 3.4? If so, which ticket should I watch for updates?

(FWIW: This did break our startup scripts, and therefore blocks our upgrade)

Comment by Githook User [ 13/Dec/16 ]

Author:

{u'username': u'Machyne', u'name': u'Matt Cotter', u'email': u'matt.cotter@mongodb.com'}

Message: SERVER-27289 fix ConnectionString parsing in shell
Branch: master
https://github.com/mongodb/mongo/commit/68c8715feaa2ead6a3c25eb9aa512de779c4795d

Comment by Githook User [ 12/Dec/16 ]

Author:

{u'username': u'Machyne', u'name': u'Matt Cotter', u'email': u'matt.cotter@mongodb.com'}

Message: Revert "SERVER-27289 fix ConnectionString parsing in shell"

This reverts commit b9c59fd5c79c0b0d9c845e3c05e50ab1dd9f7f4a.
Branch: master
https://github.com/mongodb/mongo/commit/94fefd0851c4436fd7dc7b084101a7ed59eee7ed

Comment by Githook User [ 12/Dec/16 ]

Author:

{u'username': u'Machyne', u'name': u'Matt Cotter', u'email': u'matt.cotter@mongodb.com'}

Message: SERVER-27289 fix ConnectionString parsing in shell
Branch: master
https://github.com/mongodb/mongo/commit/b9c59fd5c79c0b0d9c845e3c05e50ab1dd9f7f4a

Comment by Vick Mena (Inactive) [ 05/Dec/16 ]

mongo --host mongodb://localhost:27018/?replicaSet=replset
MongoDB shell version v3.4.0
connecting to: mongodb://localhost:27018/?replicaSet=replset

matt.cotter Full URI does work.

Comment by Matt Cotter [ 05/Dec/16 ]

This regression is likely due to the linked ticket SERVER-22382.

vick.mena can you verify that you are able to connect if you provide a full mongodb uri?

Generated at Thu Feb 08 04:14:44 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.