Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Errr 'mongo.js:L112 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112'

I can't connect to MongoDB. In Ubuntu it works, but I'm working in CentOS now. This is the error message:

MongoDB shell version: 2.4.2
connecting to: test
Sat Apr 20 07:22:09.390 JavaScript execution failed: Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112
exception: connect failed

I tried removing the mongod.lock file, but it doesn't work.

like image 571
user1992275 Avatar asked Apr 20 '13 12:04

user1992275


People also ask

Can't connect to server connection refused MongoDB?

Normally this caused because you didn't start mongod process before you try starting mongo shell. This case worked out for me, i had to do ~>sudo mongod --dbpath /dbpathlocation and then opened the new terminal to run mongo...

Why my database is not connecting in MongoDB?

If you have created a user and are having trouble authenticating, try the following: Check that you are using the correct username and password for your database user, and that you are connecting to the correct database deployment. Check that you are specifying the correct authSource database in your connection string.

How do I fix MongoDB errors?

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 connect mongo shell to server?

To open up the MongoDB shell, run the mongo command from your server prompt. By default, the mongo command opens a shell connected to a locally-installed MongoDB instance running on port 27017 . Try running the mongo command with no additional parameters: mongo.


1 Answers

If you are running Ubuntu, then there is an issue with folder ownership.

Run these commands:

  1. Stop the MongoDB service

    sudo service mongodb stop 
  2. Remove the MongoDB lock file

    sudo rm /var/lib/mongodb/mongod.lock 
  3. Change ownership from root to the MongoDB path

    sudo chown -R mongodb:mongodb /var/lib/mongodb/ 
  4. Start the MongoDB service

    sudo service mongodb start 
  5. Test the mongo application

    mongo 

Then you will be able to execute successfully (I hope).

Reference: an answer on Stack Exchange site Database Administrators to Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91 when changing mongodb data directory!

like image 59
Sumit Ramteke Avatar answered Sep 17 '22 18:09

Sumit Ramteke