Intellipaat Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in SQL by (47.6k points)

I'm getting the following error:

alex@alex-K43U:/$ mongo 

MongoDB shell version: 2.2.0 

connecting to: test 

Thu Oct 11 11:46:53 Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91 

exception: connect failed 

alex@alex-K43U:/$

This is what happens when I try to start MongoDB:

* Starting database mongodb [fail]

I already tried mongo --repair

I made chown and chmod to var, lib, and data/db and log MongoDB.

Not sure what else to do. Any suggestions?

2 Answers

+1 vote
by (106k points)

To connect to the server you must run the commands below in order to get up the mongod process:

sudo service mongodb stop 

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

sudo mongod --repair --dbpath /var/lib/mongodb 

sudo mongod --fork --logpath /var/lib/mongodb/mongodb.log --dbpath /var/lib/mongodb 

sudo service mongodb start

0 votes
by (107k points)

I think there is a lock file that terminates the MongoDB. You have to remove the lock file that is present and then run your repair command. after the repair command, restart your MongoDB. 

For removing the lock file:

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

For repairing:

sudo mongod --repair 

Start your MongoDB.

sudo start mongodb 

or

sudo service mongodb start

After that kindly check the status of your MongoDB with the help of the following command:

sudo status mongodb 

or   

sudo service mongodb status

And then at last just start your mongo shell with the help of the following code:

mongo  

31k questions

32.8k answers

501 comments

693 users

Browse Categories

...