Cannot connect to mongodb errno:61 Connection refused
It can happen when the mongodb service is not running on the mac. To start it, I tried
brew services start mongodb
and it worked.
Edit: According to the discussion on this PR on homebrew: https://github.com/Homebrew/homebrew/issues/30628
brew services
is deprecated, I looked around on SO and found these answers now answer the question: What is the correct way to start a mongod service on linux / OS X?
I encountered the exact same issue and here is a clear step by step process to avoid this error.
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. I have also detailed the error trace and its solution on this blog.
To solve your issue you need to follow the instructions which are then given to you by brew after you use "brew install mongodb".
To have launchd start mongodb at login:
ln -sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
Then to load mongodb now:
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
Or, if you don't want/need launchctl, you can just run:
mongod --config /usr/local/etc/mongod.conf
You may be able to just run that last command, but it didn't work for me and I needed to run the second command. To save me in the future. I just ran the first command too. Hope that helps!
EDIT Hrishi's method of using brew services mongodb start
worked good for me. I think they should include this in the mongo docs.