1

I was following along a course and entered a command that was given

mongod --dbpath=data --bind_ip 127.0.0.1

In the past, I had used mongo and it had worked, but I'm sure I had never entered this command. Now when I try to launch mongo via terminal I get this error:

MongoDB shell version v4.4.0
connecting to: mongodb://127.0.0.1:27017/?compressors=disabled&gssapiServiceName=mongodb
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 :
connect@src/mongo/shell/mongo.js:362:17
@(connect):2:6
exception: connect failed
exiting with code 1

Whenever I try to start up mongod I get this error:

{"t":{"$date":"2020-08-24T10:50:51.683+02:00"},"s":"I",  "c":"CONTROL",  "id":23285,   "ctx":"main","msg":"Automatically disabling TLS 1.0, to force-enable TLS 1.0 specify --sslDisabledProtocols 'none'"}
{"t":{"$date":"2020-08-24T10:50:51.715+02:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-08-24T10:50:51.716+02:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2020-08-24T10:50:51.721+02:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":51965,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"22biedermann-p"}}
{"t":{"$date":"2020-08-24T10:50:51.721+02:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.0","gitVersion":"563487e100c4215e2dce98d0af2a6a5a2d67c5cf","modules":[],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-08-24T10:50:51.722+02:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"18.7.0"}}}
{"t":{"$date":"2020-08-24T10:50:51.722+02:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2020-08-24T10:50:51.731+02:00"},"s":"E",  "c":"STORAGE",  "id":20557,   "ctx":"initandlisten","msg":"DBException in initAndListen, terminating","attr":{"error":"NonExistentPath: Data directory /data/db not found. Create the missing directory or specify another path using (1) the --dbpath command line option, or (2) by adding the 'storage.dbPath' option in the configuration file."}}
{"t":{"$date":"2020-08-24T10:50:51.732+02:00"},"s":"I",  "c":"NETWORK",  "id":20562,   "ctx":"initandlisten","msg":"Shutdown: going to close listening sockets"}
{"t":{"$date":"2020-08-24T10:50:51.732+02:00"},"s":"I",  "c":"-",        "id":20520,   "ctx":"initandlisten","msg":"Stopping further Flow Control ticket acquisitions."}
{"t":{"$date":"2020-08-24T10:50:51.733+02:00"},"s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"initandlisten","msg":"Now exiting"}
{"t":{"$date":"2020-08-24T10:50:51.733+02:00"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":100}}

I have been googling and trying to find different solutions but I have no clue how to proceed. I am using Mac OS.

2 Answers 2

1

The reason it is failing is right there in the logs:

Data directory /data/db not found

If you start mongod with no dbPath parameter it will default to /data/db. On your system, if you have used MongoDB in the past it must have been with a different dbPath or you have since deleted that path. I suggest you either specify a different path or create the /data/db folder for MongoDB to store its data.

-2

this worked for me:

sudo mkdir -p /data/db

sudo chmod 777 /data/db
1
  • Hi, and welcome to the forum! What is wrong with the accepted answer. I not saying you're wrong - but maybe you could expand on your answer? It seems to me that providing a $PATH to mongodb is a better solution than the "sledgehammer" approach of making everything 777? May 6, 2021 at 6:31

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.