title: MongoDB running but can't connect using shell
body: <p>CentOS 5.x Linux with MongoDB 2.0.1 (tried main and legacy-static)</p>
  
  <p>MongoDB is running:</p>
  
  <pre><code>root     31664  1.5  1.4  81848 11148 ?        Sl   18:40   0:00 ./mongod -f mongo.conf -vvvvv --fork
  </code></pre>
  
  <p>Using a simple shell connect to get to the server fails:</p>
  
  <pre><code>[root@xxxx bin]# ./mongo
  MongoDB shell version: 2.0.1
  connecting to: test
  Mon Oct 31 18:41:32 Error: couldn't connect to server 127.0.0.1 shell/mongo.js:84
  exception: connect failed
  </code></pre>
  
  <p>The web interface on port 28017 loads fine, as does using the MongoDB shell from a remote Linux host. Can also telnet to localhost:27017, which means no ports are blocked. There is no SELinux running on this machine as well. I have also tried explicitly specifying <code>localhost:2017/db</code> to no avail.</p>
  
  <pre><code>$ ./mongo remote-ip:27017
  MongoDB shell version: 2.0.1
  connecting to: remote-ip:27017/test
  &gt; show dbs
  local   0.03125GB
  &gt;
  </code></pre>
  
  <p>Logs are completely mum on the subject:</p>
  
  <pre><code>.....
  Mon Oct 31 18:40:34 [initandlisten] fd limit hard:1024 soft:1024 max conn: 819
  Mon Oct 31 18:40:34 [initandlisten] waiting for connections on port 27017
  Mon Oct 31 18:40:34 BackgroundJob starting: snapshot
  Mon Oct 31 18:40:34 BackgroundJob starting: ClientCursorMonitor
  Mon Oct 31 18:40:34 BackgroundJob starting: PeriodicTask::Runner
  Mon Oct 31 18:40:34 [websvr] fd limit hard:1024 soft:1024 max conn: 819
  Mon Oct 31 18:40:34 [websvr] admin web console waiting for connections on port 28017
  </code></pre>
  
  <p>Stracing the mongo shell client shows only one problematic call:</p>
  
  <pre><code>[pid 31708] connect(4, {sa_family=AF_INET, sin_port=htons(27017), sin_addr=inet_addr("127.0.0.1")}, 16) = -1 EBADF (Bad file descriptor)
  </code></pre>
  
  <p>Filesystem is clean, no ulimit restrictions (running as root for testing). I can see from the strace that the <code>mongo</code> client is trying to connect via TCP (<code>AF_INET</code>), but since it is local and MongoDB creates a file socket, is there a way to tell the client to connect through that instead? Or better yet, why would the client be throwing a EBADF?</p>
  
  <p>EDIT: My basic Mongo conf:</p>
  
  <pre><code>dbpath=/root/mongodb-linux-i686-2.0.1/data
  logpath=/root/mongodb-linux-i686-2.0.1/logs/mongo.log
  slowms=15
  rest=1
  </code></pre>