Couldn't connect to server 127.0.0.1:27017 connection attempt failed MongoDB
mongod --repair worked for me ,
sudo mongod --repair
sudo mongod
Then open a different tab/terminal:
mongo
After this your local setup will work properly
This worked for me (MAC):
Step 1 : Check the status if MongoDB is running or not
brew services list | grep mongo
Step 2 : if you get something like :
Name Status User Plist
mongodb stopped
Step 3: : start the service:
brew services start mongodb
else :
if you get like this after step 2:
Name Status User Plist
mongodb started u1 /Users/u1/Library/LaunchAgents/homebrew.mxcl.mongodb.plist
then it is already running then you can restart your service by
brew services restart mongodb
This error occurs when your mongodb server
is not running on 27017
port.
Try the below command to start the mongodb server.
sudo systemctl start mongod
And after running this command run the mongo
command.