[SERVER-14762] mongo shell - host name misinterpretation ? Created: 01/Aug/14  Updated: 10/Dec/14  Resolved: 01/Aug/14

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

Type: Bug Priority: Minor - P4
Reporter: Emmanuel Jacobs Assignee: Ramon Fernandez Marina
Resolution: Done Votes: 0
Labels: None
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Operating System: ALL
Steps To Reproduce:

Create a host entry for interface IP address (not localhost)
launch mongod with --bind_ip ChosenHostname
try to connect shell with "mongo ChosenHostname" and "mongo ChosenHostname:27017"

Participants:

 Description   

Using Windows I have an IP-name association in the host file which is "rs01 25.1.1.1" checked with:
>ping rs01
Pinging rs01 [25.1.1.1] with 32 bytes of data:
Reply from 25.1.1.1: bytes=32 time<1ms TTL=128
...
mongod is launched with "--bind_ip rs01"
Proper binding checked with:
>netstat -an | grep 27017
STDIN
TCP 25.1.1.1:27017 0.0.0.0:0 LISTENING
When typing "mongo rs01" shell try and fail to connect to 127.0.0.1
>mongo rs01
MongoDB shell version: 2.6.3
connecting to: rs01
2014-08-01T11:13:57.206+0200 warning: Failed to connect to 127.0.0.1:27017, reason: errno:10061 No connection could be made because the target machine actively refused it.
2014-08-01T11:13:57.211+0200 Error: couldn't connect to server 127.0.0.1:27017 (127.0.0.1), connection attempt failed at src/mongo/shell/mongo.js:146
exception: connect failed

When typing "mongo rs01:27017" shell connect to correct IP
>mongo rs01:27017
MongoDB shell version: 2.6.3
connecting to: rs01:27017/test
> exit
bye



 Comments   
Comment by Emmanuel Jacobs [ 01/Aug/14 ]

Thx, sorry for my misunderstanding...

Comment by Ramon Fernandez Marina [ 01/Aug/14 ]

manette, the first argument to mongo is the name of the database to connect to, so

mongo rs01

means "connect to the rs01 database on the local machine", and since your mongod instance is not listening on 127.0.0.1 the connection fails. When you run

mongo rs01:27017

that means "connect to the default database (test) on machine rs01, port 27017, and the connection succeeds because mongod is listening on rs01:27017. If you want to use your host name to connect, you can run

mongo rs01/test

Regards,
Ramón.

Generated at Thu Feb 08 03:35:54 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.