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

user1992275 picture user1992275 · Apr 20, 2013 · Viewed 36.3k times · Source

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.

Answer

Sumit Ramteke picture Sumit Ramteke · Jun 1, 2013

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!