Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mongo: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145

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 is

E: 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

like image 480
micobg Avatar asked Oct 22 '13 20:10

micobg


People also ask

Why MongoDB Cannot connect to server?

These are some of the solutions: Ensure that your MongoDB instance is running: Compass must connect to a running MongoDB instance. Also check you have installed MongoDB and have a running mongod process. You should also check that the port where MongoDB is running matches the port you provide in the compass connect.

How do I connect to localhost 27017?

To connect to your local MongoDB, you set Hostname to localhost and Port to 27017 . These values are the default for all local MongoDB connections (unless you changed them). Press connect, and you should see the databases in your local MongoDB.

How do I allow remote access to MongoDB?

MongoDB can be managed remotely or connected to a separate application server by making a few changes to the default configuration. First, we'll install the MongoDB using the docker container, then configure the MongoDB installation to access from a trusted remote machine securely.


2 Answers

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.

like image 57
Salvador Dali Avatar answered Sep 19 '22 20:09

Salvador Dali


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.

like image 43
arulraj.net Avatar answered Sep 18 '22 20:09

arulraj.net