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

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

As a learner in mongodb I don’t get understand why this problem often occur in Linux machine. But Luckily somehow I figured out a way to resolve this issue with the help of few mongodb experts outs there on internet. Below is the way I followed to put an end to the starting trouble of mongodb. 

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

Step 2) Repair mongodb.
mongod –repair

Step 3) start mongodb.
sudo service mongodb start
(or)
sudo start mongodb

Step 4) Check status of mongodb.
sudo service mongodb status
(or)
sudo status mongodb

Step 5) Start mongo console.
mongo

that’s it,above commands would have instructed mongodb to repair the broken piece and start the new instance for us to continue.


7 Comments

  1. Philippe Thomas wrote
    at 9:32 AM - 1st February 2014 Permalink

    Simply the best way I ve found so far to fix the problem, I had really no clue how it happened tough.

    Thanks Mate !

  2. Duncan wrote
    at 7:04 AM - 19th May 2014 Permalink

    Thanks.. worked for me too. much appreciated.

  3. shakthydoss wrote
    at 9:15 AM - 19th May 2014 Permalink

    I am glad it helped you.

  4. Duncan wrote
    at 1:34 AM - 19th May 2014 Permalink

    Thanks.. worked for me too. much appreciated.

  5. shakthydoss wrote
    at 3:45 AM - 19th May 2014 Permalink

    I am glad it helped you.

  6. javaMan wrote
    at 8:33 AM - 31st July 2014 Permalink

    I do need the above commands for Windows.
    Is there anybody to resolve this problem?

  7. anonymous wrote
    at 12:24 PM - 6th February 2015 Permalink

    That works thanks. Only thing is in step 4 and 5 use “mongod” instead of “mongodb”.

Post a Comment

Your email is never published nor shared. Required fields are marked *