Thursday, 21 May 2015

Resolve the connection problem in mongoDB


I was trying to set up admin password in mongoDB by using admin database, but something went wrong and I started getting  error " couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:145exception: connect failed".
After giving some trials I rectified using the following commands :

Step 1: Remove lock file.
sudo rm /var/lib/mongodb/mongod.lock

Step 2: Repair mongodb.
sudo mongod --repair

Step 3: start mongodb.
sudo start mongodb
or
sudo service mongodb start

Step 4: Check status of mongodb.
sudo status mongodb
or  
sudo service mongodb status

Step 5: Start mongo console.
mongo


Reference : http://stackoverflow.com/questions/12831939/couldnt-connect-to-server-127-0-0-127017/17793856#17793856