This error can happen when the MongoDB service is not running on the mac while you involved in full-stack Django development and developing an application using MongoDB as the database backend. When the user tries to access the mongo shell by using the mongo command but got an error;
“Cannot connect to MongoDB error:61 connection refused.”
This error can be solved in many ways;
To solve your issue, you have to follow the instructions which are given to you by brew after your “brew install MongoDB”.
To launched start the MongoDB at login;
ln –sfv /usr/local/opt/mongodb/*.plist ~/Library/LaunchAgents
Then load the MongoDB again by using the command;
launchctl load ~/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
If you don’t need to launchtl, you can just run the following command;
mongod –config /usr/local/etc/mongod.conf
Install the MongoDB by using the brew install command, if you already have MongoDB then you don’t need to follow this step;
brew install mongodb
Run the MongoDB Daemon by using the command;
mkdir –p /data/db
Now run the mongo shell interface by using the command;
In this sequence, you can be able to run the mongo command without any error.