Are you facing an issue with your MongoDB which says "Address already in use for socket"? Don't worry.. Tips to fix it is available in this article.
As part of our Server Support Services, we have previously helped customers fix MongoDB related errors.
This context will show you why this error occurs and how to get rid of it.
Most MongoDB users sometimes experience such an error which occurs when the port assigned to the database is used by another process at the same time. This will prevent MongoDB from accessing it and throw an error in response to failure to use the port.
Fixing this error is logical in that you can simply stop the process which is using the port.
Lets see how to get this done;
i. Assigning another port for use by MongoDB
You can allow MongoDB use a different port via the command below;
mongod –port new_port_number
In this case, use the port you want to assign to MongoDB in place of "new_port_number" to get a fix to this issue.
ii. Kill the running process occupying the port.
You can simply kill the process occupying the port to be used by MongoDB by first searching the running tasks in the system. Use the command below;
sudo lsof -iTCP -sTCP:LISTEN -n -P
This will list all the running processes. Once you locate the particular process using the port, then proceed with the kill process by using the command below;
sudo kill <pid_of_running_process>
Here, replace "pid_of_running_process" with the actual pid of the process occupying the port and after which you can run MongoDB with the command below;
mongod
This will enable MongoDB to function correctly.
Best Method to get rid of Mongodb Socket error address already in use in Linux.