[SERVER-27495] When given an invalid address, client connects to localhost Created: 22/Dec/16  Updated: 27/Oct/23  Resolved: 07/Jan/17

Status: Closed
Project: Core Server
Component/s: Shell
Affects Version/s: 3.5.1
Fix Version/s: None

Type: Bug Priority: Major - P3
Reporter: Guilherme Marconi Assignee: Andrew Morrow (Inactive)
Resolution: Works as Designed Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Attachments: PNG File evidence.png    
Operating System: ALL
Sprint: Platforms 2017-01-23
Participants:

 Description   

When connecting using mongo client (command line, windows), if the address given is invalid, mongo client will connect to localhost instance, without giving any errors. This happens if you provide only a part of the server full URI. Example:

mongo myserver -> connects to localhost, no error message. nslookup myserver returns server ip address, not mine.

mongo myserver.fulldomain.com -> connects to myserver correctly.

Not sure if it's a bug or it's by design (a previously taken decision), and I wasn't able to find anything on the matter. If it's by design I'd vote to change this to improvement and ask for a warning message (someone might really think they are acting on 'myserver' when it's acting on 'localhost' really - and if both localhost and myserver belongs to the same replicaSet, the prompt will be the same 'replicaSetName:SECONDARY').



 Comments   
Comment by Andrew Morrow (Inactive) [ 07/Jan/17 ]

marconi - I'm resolving this ticket as "Works as Designed" because I believe this represents the documented behavior. Please feel free to re-open this ticket if you have any further thoughts on the issue, or require additional assistance.

Comment by Andrew Morrow (Inactive) [ 03/Jan/17 ]

While I agree that it may be somewhat confusing, this is the expected behavior. Please note the following output from the shell when run with --help:

$ ./mongo --help
MongoDB shell version v3.5.1-110-g1346352
usage: ./mongo [options] [db address] [file names (ending in .js)]
db address can be:
  foo                   foo database on local machine
  192.168.0.5/foo       foo database on 192.168.0.5 machine
  192.168.0.5:9999/foo  foo database on 192.168.0.5 machine on port 9999

In your case, the single argument is being interpreted as the name of a database - not the name of a host. If you wish to specify both the host and the database, use one of the other indicated formats.

Also, please note that while the help output does not show it, modern versions of the MongoDB shell support much of the MongoDB URI syntax (i.e. mongo mongodb://...). You might do better to switch to using that format, as it makes it much clearer what is going on, generally. When using this syntax, the host name is always required, so there is no ambiguity.

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