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

Have you got Error:  MongoDB shell version: 2.4.5 connecting to: test Fri 1 13: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 in your terminal on linux or mac?






You can get rid of this error using following steps.


    Stop mongodb service

    sudo service mongodb stop

    Remove mongodb lock file

    sudo rm /var/lib/mongodb/mongod.lock

    Change ownership from root to mongodb path

    sudo chown -R mongodb:mongodb /var/lib/mongodb/

    Start mongodb service

    sudo service mongodb start

    Test mongo app

    mongo