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
This method only works if you want to repair your data files without preserving the original files. To find where you dbpath resides, use
vim /etc/mongodb.conf
Check for option dbpath=
.
(I have dbpath=/var/lib/mongodb
.)
Default: /data/db/
Typical locations include /srv/mongodb
, /var/lib/mongodb
or /opt/mongodb
.
Replace the /var/lib/mongodb with your dbpath
sudo rm /var/lib/mongodb/mongod.lock
sudo mongod --dbpath /var/lib/mongodb/ --repair
sudo mongod --dbpath /var/lib/mongodb/ --journal
(Make sure that you leave you terminal running in which you have run the above lines. Don't press Ctrl + C or quit it.) Type the command to start mongo
now in another window.
I hope this works for you! For those who want to repair your data files while preserving the original files, see mongo recover.