i found this error when trying to run mongodb. I install it via homebrew. Please assist
Agungs-MacBook-Pro:~ agungmahaputra$ mongod
2017-12-26T15:31:15.911+0
You already have a process running in the port 27017
which is used by mongodb
. So either you need to stop the process in that port or try with different port number.
Try mongod --port 27018
You can change the port number of your choice.
EDIT:
You can also just stop all the running instances of mongo server using
sudo killall mongod
as mentioned by @Dassi Orleando in the comments.
And run mongod
Make Sure the error is of the port , if using macos catalina there is a reported issue for ~/data/db which also causes this.
sudo pkill -f mongod
Summary other(@Tony Roczz
, @Balasubramani M
) answer to here:
error: Failed to set up listener: SocketException: Address already in use
means:
27017
mongod
two method:
killall mongod
ps aux | grep mongod
limao 425 ... /usr/local/opt/mongodb-community/bin/mongod --config /usr/local/etc/mongod.conf
lsof -iTCP -sTCP:LISTEN -n -P
mongod 425 limao .. TCP 127.0.0.1:27017 (LISTEN)
kill -9 425
mongod
brew services start mongodb-community
brew install mongodb-community
mongod --port 27018
lsof -iTCP -sTCP:LISTEN -n -P
COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME
mongod 425 limao 10u IPv4 0xab744305e75263cf 0t0 TCP 127.0.0.1:27017 (LISTEN)
can see 27017
is current running mongodb port.
ps aux | grep mongod
mongod
servicebrew services list
brew
and start by brew
This may sound obvious but you should check if mongodb is already running. So instead of first starting the the DB by running:
sudo mongod
Try directly running:
mongo
You can kill the previous mongod instance and start the new one.
To kill the previous mongod instance, first search for a list of tasks running on your machine by typing,
sudo lsof -iTCP -sTCP:LISTEN -n -P
Search for mongod COMMAND and its PID and type,
sudo kill <mongo_command_pid>
Now start your mongod instance by typing,
mongod
You can see MongoDB running successfully.