mongo - couldn't connect to server 127.0.0.1:27017 mongo - couldn't connect to server 127.0.0.1:27017 mongodb mongodb

mongo - couldn't connect to server 127.0.0.1:27017


Normally this caused because you didn't start mongod process before you try starting mongo shell.

Start mongod server

mongod

Open another terminal window

Start mongo shell

mongo


Resolved.

This problem could be solved by the below mentioned 4 steps

1) Remove .lock file

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

2) repair the mongodb

mongod -–repair

3) start the mongod server

sudo service mongod start 

4) start the mongo client

mongo

For more details take a look at http://shakthydoss.com/error-couldnt-connect-to-server-127-0-0-127017-srcmongoshellmongo-js-exception-connect-failed/

http://shakthydoss.com/technical/error-couldnt-connect-to-server-127-0-0-127017-srcmongoshellmongo-js-exception-connect-failed/


This method only works if you want to repair your data files without preserving the original files

To find where you dbpath resides- 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.locksudo mongod --dbpath /var/lib/mongodb/ --repairsudo mongod --dbpath /var/lib/mongodb/ --journal

(Make sure that you leave you terminal running in which you have run above lines, dont press 'Ctrl+c' or quit it.) Type the command to start mongo now in another window.

Hope this works for you ! for those who want to repair your data files while preserving the original filesmongo recover