I just updated my mac to Catalina 10.15.2 and I can't running MongoDB.
When I send the command mongo
I receive this message
Error: couldn't connect to server 127.0.0.1:27017, connection attempt failed: SocketException: Error connecting to 127.0.0.1:27017 :: caused by :: Connection refused :
and the only way to make Mongo work is to restart the Mac.
If I check the process with the command ps
I don't see the process already on and the port 27017 is available.
I already tried to run the follow command:
brew tap mongodb/brew
brew reinstall mongodb-community
brew services restart mongodb-community
and if I run the follow command:
ps aux | grep -v grep | grep mongod
no results.
I tried to run mongod
before mongo
as well and the result is:
2019-12-18T12:17:45.916+0100 I CONTROL [main] Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] MongoDB starting : pid=9375 port=27017 dbpath=/data/db 64-bit host=Marcos-MacBook-Pro.local
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] db version v4.2.1
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] git version: edf6d45851c0b9ee15548f0f847df141764a317e
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] allocator: system
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] modules: none
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] build environment:
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] distarch: x86_64
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] target_arch: x86_64
2019-12-18T12:17:45.920+0100 I CONTROL [initandlisten] options: {}
2019-12-18T12:17:45.920+0100 E NETWORK [initandlisten] Failed to unlink socket file /tmp/mongodb-27017.sock Permission denied
2019-12-18T12:17:45.920+0100 F - [initandlisten] Fatal Assertion 40486 at src/mongo/transport/transport_layer_asio.cpp 693
2019-12-18T12:17:45.920+0100 F - [initandlisten]
***aborting after fassert() failure
Someone can help me please? I appreciate it
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.
0.1 : 27017 ” is a general error message indicating that your client/driver cannot connect to a server on the specified hostname/IP and port. In this specific example, 127.0. 0.1 is the hostname or IP and 27017 is the port. Your connection from client to server is blocked by firewall or network configuration.
Normally this caused because you didn't start mongod process before you try starting mongo shell. This case worked out for me, i had to do ~>sudo mongod --dbpath /dbpathlocation and then opened the new terminal to run mongo...
An alternative way to fix this Catalina Mac OS root & mongodb connection issue, do the following:
Install Homebrew, if you have it, reinstall it again
run the following commands in the terminal
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)" brew untap mongodb/brew && brew tap mongodb/brew brew install [email protected]
The issue is mongo cannot find /db/data
because there is no directory, so you have to create one:
cd ~
(this should take you to your Users
folder)
from the Users
folder make your own db/data folder by running the follow commands:
mkdir db
& cd inside db folder
inside the db folder
run: mkdir data
& cd inside data folder
run this command: mongod --dbpath ~/data/db
(inside the Users/data/db/
folder you just created)
Now open a new tab &
run: cd ~
(brings you back to Users) -> now run : cd .. & cd .. again (do this twice)
(now you should be in the folder before Users)
(now find tmp folder
) cd into the /tmp folder
delete the sock file (this is giving you connection issues)
delete it by running: rm -rf mongodb-27017.sock
now run command: mongo
(this should work now)
inside mongo shell run command: db.verion()
if you see a version, your connection works.
From now on to run mongodb database & connection you will have to have to tabs open at all times whenever you want to work on your projects
Example: in one tab run command -> mongod --dbpath ~/data/db (this starts the connection) in the other tab run command: mongo (this starts the shell)
These both have to be running..
Side Note: you no longer need to start the connection by running brew services start mongo-community anymore.
remember mongod --dbpath ~/data/db
is basically -> mongod
command now.. The Mac OS Catalina Update created root permission problems, that is why mongod
command alone never worked before.
Hope this helped you. Goodluck.
Faced a similar issue with macOS Big Sur. After trying all the approaches mentioned above including
/System/Volumes/Data/data/dbfolder
This command worked for me mongod --dbpath=/System/Volumes/Data/data/db
reference: https://medium.com/codespace69/mongodb-troubleshooting-errors-for-beginners-and-macos-catalina-31befd99f6c8
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