Mongo: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
Solution 1
I assume that you followed the steps, outlined here.
Most probably you have a problem with mongo lock (or at least I had it once while installing on ubuntu). I solved it with the following commands:
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongodb restart
P.S. I by myself recently experienced this problem when I was updating my amazon ec2
instance. I have not properly shut down mongo before doing this and this resulted in a problem with mongo lock.
Solution 2
Check your log file of mongodb. you will get to know the exact issue.
tail -f /var/log/mongodb/mongodb.log
The issue may because of "ERROR: Insufficient free space for journal files"
Increase your volume space that will fix your issue.
Solution 3
If you got this after a restart... Make sure that you have over 3GB+ of space free else Mongo Won't start.
Solution 4
even i had the same problem so i deleted the mongod lock file
sudo rm /var/lib/mongodb/mongod.lock
and the restart the server it worked , restarting by command below
sudo service mongodb restart
Solution 5
i got the solution by changing the owner of db directory to 'mongodb'
`sudo chown -R mongodb:mongodb /data/*`
then type 'mongo'
Related videos on Youtube
micobg
Updated on July 05, 2022Comments
-
micobg almost 2 years
When I try to run mongo in shell in ubuntu or open rockmongo I see this error:
couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145
What's the reason? I tried to reinstall mongo but this didn't help. When I type
sudo apt-get purge mongodb-10gen
returned error isE: Sub-process /usr/bin/dpkg returned an error code (1)
I tried this:
- first remove line about mongo in /etc/apt/sources.list
-
run this commands:
sudo dpkg pr mongofb-10gen
sudo apt-get -f install
sudo apt-get upadte
sudo apt-get upgrade
then
sudo apt-get purge mongodb-10gen
is successful-
at the end:
sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10
-
add deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist 10gen in /etc/apt/sources.list
sudo apt-get update
sudo apt-get install mongodb-10gen
Then when I try to start mongo i saw the same error. :o
-
micobg over 10 yearsWhen I type sudo service mongodb start and then mongo the result is the same. :/ @Ketih Nicholas, is that what you asked me?
-
Brian Knight over 10 yearsDid you look in the mongod log? Is the server starting properly?
-
zero323 over 10 yearsWhat do you get when you run
sudo netstat -plnt | grep 27017
?
-
User 1058612 over 10 yearsThis worked for me; the drive mongo was running on was close to full. Made some room, did a
sudo service mongodb restart
, and all was good.