MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
I use macOS montery (intel)
Nomatter what I try. I get this error. Please help!!!
MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017
I use macOS montery (intel)
Nomatter what I try. I get this error. Please help!!!
Hello @Mohammed_Faraz and welcome to the MongoDB community forums.
It sounds like the database engine is not running so there’s nothing to connect to.
Can you state how you installed MongoDB? If you used brew
, you can start things up using brew service start mongodb-commmunity
. This will start the system up. You can then use brew services
to verify that it’s running. If there are errors you would need to check the log file for MongoDB to determine what’s going on.
If you manually installed MongoDB by downloading the compressed files and are running the mongod
process manually, then we would need to know more about the exact command line parameters you’re using and any log information on why the process is not starting up.
Thanks for the reply. I tried using “sudo mkdir -p /System/Volumes/Data/data/db” then “sudo chown -R id -un
/System/Volumes/Data/data/db” and then “sudo mongod --dbpath /System/Volumes/Data/data/db”.
It worked!
I tried these commands after installing via brew yesterday and they didn’t work but somehow now its working. Don’t know how! Do you have any idea how it worked this time?
The installation via brew
should have set everything up for your local user to run the mongod
process. This is the last few lines you get when running brew info mongodb-community
:
==> Caveats
To restart mongodb/brew/mongodb-community after an upgrade:
brew services restart mongodb/brew/mongodb-community
Or, if you don't want/need a background service you can just run:
mongod --config /usr/local/etc/mongod.conf
Since you’re running with sudo
on everything, you’re running the risk of security issues as the process is running under elevated privileges. Even though the data directory is owned by your user, you’re still running the process as the root
user so all the files in that path will be owned by root
and not accessible by your normal user.
After installation with brew
were you able to run brew services start mongodb-community
? That’s how I usually run things, then when I don’t need MongoDB running I just brew services stop mongodb-community
.
I was able to run brew services start mongodb-community@6.0 but when I use mongod it throws me an error “MongoNetworkError: connect ECONNREFUSED 127.0.0.1:27017”.
If I dont use sudo and I run “mongod” I get this error : ““ctx”:“initandlisten”,“msg”:“Shutting down”,“attr”:{“exitCode”:100}}”
I also get this error: “ctx”:“initandlisten”,“msg”:“Shutting down”,“attr”:{“exitCode”:48}}
after using : "brew services start mongodb/brew/mongodb-community "
and then “mongod”. Something is wrong and I cannot figure out.
I don’t think I’ve ever seen mongod
throw an ECONNREFUSED error. I would expect something like that from mongosh
if the server was not up and running when connecting.
The exitCode
100 was thrown most likely due to your normal user not being able to write to the data files due to permission errors.
The exitCode
48 means that there is already a server listening on the port you are trying to connect to. When you try to manually run mongod
and you still have the brew
service running, by default they will both try to connect on port 27017. You cannot run two instances of the mongod
process on the same machine unless you override the port for one of them: mongod --port 30000 ...
for example.
To see what’s happening when mongod
fails to start up, you need to look higher up in the log files. Generally there are only a couple of dozen entries if the process doesn’t want to start up and it’s not that bad to look through the files to see the exact cause.
The server generated these startup warnings when booting
2022-08-12T00:28:08.275+05:30: Access control is not enabled for the database. Read and write access to data and configuration is unrestricted.
How can I fix this? Please help.
This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.