Cannot connect to MongoDB errno:61
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 updatebrew install mongodb
Step 2 - Run Mongo Daemon:
mkdir -p /data/dbsudo mongod
Step 3 - Run Mongo Shell Interface:
mongo
In this sequence, I was able to run the mongo command without any error.
Yes, you would create /data/db
at root. The MongoDB Documentation suggests the following command for creation on OS X mkdir -p /data/db
.
Regarding your second question, also yes. Since the Mongo Daemon failed to start and isn't listening you get the connection error.
MongoDB defaults to /data/db
for the data directory. You can override the default using the --dbpath
option on the mongod
command (also on the doc link above).
** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000
you can add one line into your /etc/bashrc, the warning will disappear.
ulimit -S -n 1024
use chown -R {user} /data/db
to change the owner of /data/db
from root to yourself.Then you can start mongo shell just by mongo
, no need to use sudo mongo
.