Errr 'mongo.js:L112 Error: couldn't connect to server 127.0.0.1:27017 at src/mongo/shell/mongo.js:L112'
If you are running Ubuntu, then there is an issue with folder ownership.
Run these commands:
Stop the MongoDB service
sudo service mongodb stop
Remove the MongoDB lock file
sudo rm /var/lib/mongodb/mongod.lock
Change ownership from root to the MongoDB path
sudo chown -R mongodb:mongodb /var/lib/mongodb/
Start the MongoDB service
sudo service mongodb start
Test the mongo application
mongo
Then you will be able to execute successfully (I hope).
Reference: an answer on Stack Exchange site Database Administrators to Error: couldn't connect to server 127.0.0.1:27017 src/mongo/shell/mongo.js:91 when changing mongodb data directory!
Try to remove /var/lib/mongodb/mongod.lock and restart mongdo service
sudo rm /var/lib/mongodb/mongod.lock
sudo service mongodb restart
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.