We found that the reason for this error was the dbpath variable in /etc/mongodb. conf. Previously, the default value for dbpath was /data/db. The upstart job mongodb(which comes with mongodb-10gen package) invokes the mongod with –config /etc/mongodb.
MongoDB failed to connect to 127.0. 0.1(localhost) is the hostname and 27017 is the port number. There could be any reason for this error: Firewall or network configuration blocked you to connect to the server. The MongoDB server is not listening the IP or port.
This error comes because after installing the MongoDB database we also need to set the path of MongoDB in the system environment variable. So to resolve this error you need to follow the below steps: Open that folder where you install MongoDB. Open MongoDB folder till bin folder where mongod.exe file and copy the path.
Try:
sudo service mongod stop
sudo mongod
To stop current active mongodb service, allowing you to then start a new one
Don't kill the process using the -9 signal as it would cause damage: http://www.mongodb.org/display/DOCS/Starting+and+Stopping+Mongo#StartingandStoppingMongo-SendingaUnixINTorTERMsignal
Use sudo killall -15 mongod
instead
Andreas Jung:
"Sat Jun 25 09:38:51 [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
is self-speaking.
Another instance of mongod is already running and allocating the MongoDB default port which is 27017.
Either kill the other process or use a different port."
In this case, type the following command
ps wuax | grep mongo
You should see something that looks like this
User 31936 0.5 0.4 2719784 35624 ?? S 7:34pm 0:09.98 mongod
User 31945 0.0 0.0 2423368 184 s000 R+ 8:24pm 0:00.00 grep mongo
Now enter the kill command for the mongod instance (31936 in this case):
kill 31936
Sat Jun 25 09:38:51 [initandlisten] listen(): bind() failed errno:98 Address already in use for socket: 0.0.0.0:27017
is self-speaking.
Another instance of mongod is already running and allocating the MongoDB default port which is 27017.
Either kill the other process or use a different port.
Find out from netstat which process is running mongodb port (27017)
command:
sudo netstat -tulpn | grep :27017
Output will be:
tcp 0 0 0.0.0.0:27017 0.0.0.0:*
LISTEN 6432/mongod
In my case "6432" is the pid, it may be different in your case. Then kill that process using following command:
sudo kill <pid>
Thats it!
Use:
sudo killall mongod
It will stop the server.
Then restart mongod
by:
sudo service mongod restart
it should work.
You already have a process running. You can kill it with the command :
killall mongod
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With