Wondering how to fix the error ‘MongoDB error address already in use for socket’? We can help you fix it.
Here at Bobcares, we have seen several such MongoDB errors as part of our Server Management Services for web hosts and online service providers.
Today we’ll take a look at the causes for this error and see how to fix it.
What causes ‘MongoDB error address already in use for socket’ error to occur
This is one of the most common errors that we come across in MongoDB.
Usually, this error occurs if there is already a process running on the same port.
So MongoDB won’t be able to use this port to start or run another process on the same port.
For instance, the error appears as below.
How we fix the error ‘MongoDB error address already in use for socket’
Now let’s see how our Support Engineers assist our customers in resolving this error.
We can easily get rid of this error by either stopping the already running process or by trying to run the process from another port number.
1. Running the MongoDB in another port number
In order to run the mongod from another port number, we run the below command.
mongod –port port_number
NOTE: update the port_number value with the actual port number that you wish.
This will fix the error immediately.
2. Killing the process which is already running in the port.
In order to kill the process from the port, first, we search for the list of tasks running in the server. For that, we run the below command
sudo lsof -iTCP -sTCP:LISTEN -n -P
Now, we search for mongod command and its PID and then run the below command
sudo kill <mongo_command_pid>
As a result, this will kill the process and we can run the MongoDB by running the command,
mongod
Finally, now the MongoDB must work well normally.
[Need any further assistance in fixing MongoDB errors? – We are here to help you.]
Conclusion
In short, this error occurs if there is already a process running on the same port. Today, we saw how our Support Engineers fix this MongoDB error.
0 Comments