Cannot connect to MongoDB errno:61

Michael picture Michael · May 3, 2014 · Viewed 23.3k times · Source

I installed MongoDB using macports and tried running the mongo command in order to start the mongo shell. I received the following errors:

warning: Failed to connect to 127.0.0.1:27017, reason: errno:61 Connection refused

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

I then ran mongod and received the following error:

$ [initandlisten] MongoDB starting : pid=11984 port=27017 dbpath=/data/db 64-bit host=Nikitas-MacBook-Air.local
$ [initandlisten] 
$ [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
$ [initandlisten] db version v2.6.0
$ [initandlisten] git version: nogitversion
$ [initandlisten] build info: Darwin tennine-slave.macports.org 13.1.0 Darwin Kernel Version 
13.1.0: Thu Jan 16 19:40:37 PST 2014; root:xnu-2422.90.20~2/RELEASE_X86_64 x86_64 BOOST_LIB_VERSION=1_55
$ [initandlisten] allocator: tcmalloc
$ [initandlisten] options: {}
$ [initandlisten] exception in initAndListen: 10296 
*********************************************************************
 ERROR: dbpath (/data/db) does not exist.
 Create this directory or give existing directory in --dbpath.
 See http://dochub.mongodb.org/core/startingandstoppingmongo
*********************************************************************
, terminating
$ [initandlisten] dbexit: 
$ [initandlisten] shutdown: going to close listening sockets...
$ [initandlisten] shutdown: going to flush diaglog...
$ [initandlisten] shutdown: going to close sockets...
$ [initandlisten] shutdown: waiting for fs preallocator...
$ [initandlisten] shutdown: lock for final commit...
$ [initandlisten] shutdown: final commit...
$ [initandlisten] shutdown: closing all files...
$ [initandlisten] closeAllFiles() finished
$ [initandlisten] dbexit: really exiting now

Where do I create the /data/db directory, at root? Would the second error be the reason for the errno:61 when I run mongo?

Answer

Ali Raza Bhayani picture Ali Raza Bhayani · Feb 24, 2015

I encountered similar problem. I have detailed the error trace and solution on this blog This is step by step process I did to solve this issue:

Step 1 - Installation ( Don't follow this step if you have already installed MongoDB ):

brew update
brew install mongodb

Step 2 - Run Mongo Daemon:

mkdir -p /data/db
sudo mongod

Step 3 - Run Mongo Shell Interface:

mongo

In this sequence, I was able to run the mongo command without any error.