[SERVER-2301] In shell, the "db address" argument has ambiguous syntax Created: 29/Dec/10  Updated: 21/Aug/18  Resolved: 21/Aug/18

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

Type: Improvement Priority: Minor - P4
Reporter: Roy Smith Assignee: DO NOT USE - Backlog - Platform Team
Resolution: Done Votes: 2
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Duplicate
Participants:

 Description   

If you run "mongo foo", the argument "foo" could be either a hostname or database name. For example:

mongo db1-1.songza.com # this is a hostname to connect to
mongo db1-1 # this was intended to be a hostname, but....

In the example above (a mistake I've made numerous times), if the name resolver search path isn't set up right, "db1-1" doesn't resolve to a hostname, so the shell assumes it's a database name. The fact that the database doesn't exist is not an error, so you just get:

connecting to: db1-1

which looks VERY much like what you expected, but it's not. You're connected to localhost.

It would be better if the syntax was changed to be unambiguous. For example:

foo/bar ==> database bar on host foo
foo ==> host foo, no database specified
/bar ==> localhost, database bar

would eliminate these types of easy-to-make, difficult-to-detect errors.



 Comments   
Comment by Matt Lord (Inactive) [ 21/Aug/18 ]

Hi roysmith,

I'm closing this for now as I cannot repeat the issue in 4.0: 

mongolord:mongodb-osx-x86_64-enterprise-4.0.1 matt$ ./bin/mongo --version 
MongoDB shell version v4.0.1
git version: 54f1582fc6eb01de4d4c42f26fc133e623f065fb
allocator: system
modules: enterprise 
build environment:
    distarch: x86_64
    target_arch: x86_64
 
mongolord:mongodb-osx-x86_64-enterprise-4.0.1 matt$ ./bin/mongo mydb
MongoDB shell version v4.0.1
connecting to: mongodb://127.0.0.1:27017/mydb
MongoDB server version: 4.0.1
 
mydb@mongolord> exit
bye
 
mongolord:mongodb-osx-x86_64-enterprise-4.0.1 matt$ ./bin/mongo mydb.com
MongoDB shell version v4.0.1
connecting to: mongodb://mydb.com:27017/test
2018-08-21T09:35:55.772-0400 E QUERY    [js] Error: couldn't connect to server mydb.com:27017, connection attempt failed: HostNotFound: Could not find address for mydb.com:27017: SocketException: Host not found (authoritative) :
connect@src/mongo/shell/mongo.js:257:13
@(connect):1:6
exception: connect failed
 
mongolord:mongodb-osx-x86_64-enterprise-4.0.1 matt$ 
  

If I missed something please let me know and I can re-open the ticket.

Thank you for using MongoDB!

Comment by Asya Kamsky [ 16/Aug/18 ]

The shell does show what it's doing now:

mongo foo
MongoDB shell version v4.0.0
connecting to: mongodb://127.0.0.1:27017/foo
 
mongo foo.com
MongoDB shell version v4.0.0
connecting to: mongodb://foo.com:27017/test 

Comment by Roy Smith [ 30/Dec/10 ]

At the very least, if the shell said, "connecting to: host=localhost, db=db1-1", at least there would be some useful feedback that things were not going as you expected.

But, making the syntax unambiguous would be better.

Comment by Eliot Horowitz (Inactive) [ 29/Dec/10 ]

Agreed its a bit strange, though a lot of people like it.
Hard to tell if its overall good or bad.

Generated at Thu Feb 08 02:59:33 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.