0

I'm trying to get a localhost MongoDB DB working, but I don't get it. I use Mac.

Here is what I write in the shell (zsh) :

mongo

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

Also, when I write this :

mongod

I get this :

{"t":{"$date":"2020-09-07T12:01:27.943+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-09-07T12:01:27.945+02:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-09-07T12:01:27.945+02:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2020-09-07T12:01:27.946+02:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-09-07T12:01:27.946+02:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":2652,"port":27017,"dbPath":"/data/db","architecture":"64-bit","host":"MBP-de-Gaetan"}}
{"t":{"$date":"2020-09-07T12:01:27.946+02:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.0","gitVersion":"563487e100c4215e2dce98d0af2a6a5a2d67c5cf","modules":["enterprise"],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-09-07T12:01:27.946+02:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"19.6.0"}}}
{"t":{"$date":"2020-09-07T12:01:27.946+02:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{}}}
{"t":{"$date":"2020-09-07T12:01:27.947+02:00"},"s":"E",  "c":"NETWORK",  "id":23024,   "ctx":"initandlisten","msg":"Failed to unlink socket file","attr":{"path":"/tmp/mongodb-27017.sock","error":"Permission denied"}}
{"t":{"$date":"2020-09-07T12:01:27.947+02:00"},"s":"F",  "c":"-",        "id":23091,   "ctx":"initandlisten","msg":"Fatal assertion","attr":{"msgid":40486,"file":"src/mongo/transport/transport_layer_asio.cpp","line":919}}
{"t":{"$date":"2020-09-07T12:01:27.947+02:00"},"s":"F",  "c":"-",        "id":23092,   "ctx":"initandlisten","msg":"\n\n***aborting after fassert() failure\n\n"}

it also doesn't work with node when I try to connect to local DB. Ultimately, I want to connect to a local db via node using 'Dotenv' and this line of code : DATABASE=mongodb://localhost:27017/node-form

but I get error again :

mongodb://localhost:27017/node-form
-: Connection error: connect ECONNREFUSED 127.0.0.1:27017 :-
(node:2930) UnhandledPromiseRejectionWarning: MongooseServerSelectionError: connect ECONNREFUSED 127.0.0.1:27017
    at new MongooseServerSelectionError (/Users/gaetan/WorkSpace/Back et front/Back/Fichiers_de_cours/node-forms_4/node_modules/mongoose/lib/error/serverSelection.js:24:11)
    at NativeConnection.Connection.openUri (/Users/gaetan/WorkSpace/Back et front/Back/Fichiers_de_cours/node-forms_4/node_modules/mongoose/lib/connection.js:823:32)
    at Mongoose.connect (/Users/gaetan/WorkSpace/Back et front/Back/Fichiers_de_cours/node-forms_4/node_modules/mongoose/lib/index.js:333:15)
    at Object.<anonymous> (/Users/gaetan/WorkSpace/Back et front/Back/Fichiers_de_cours/node-forms_4/start.js:8:10)
    at Module._compile (internal/modules/cjs/loader.js:1138:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:1158:10)
    at Module.load (internal/modules/cjs/loader.js:986:32)
    at Function.Module._load (internal/modules/cjs/loader.js:879:14)
    at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:71:12)
    at internal/main/run_main_module.js:17:47
(node:2930) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1)
(node:2930) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.

here with an other port :

gaetan@MacBook-Pro-de-Gaetan ~ % mongod --port 27018
{"t":{"$date":"2020-09-07T12:18:16.133+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-09-07T12:18:16.133+02:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-09-07T12:18:16.133+02:00"},"s":"I",  "c":"NETWORK",  "id":4648602, "ctx":"main","msg":"Implicit TCP FastOpen in use."}
{"t":{"$date":"2020-09-07T12:18:16.135+02:00"},"s":"W",  "c":"ASIO",     "id":22601,   "ctx":"main","msg":"No TransportLayer configured during NetworkInterface startup"}
{"t":{"$date":"2020-09-07T12:18:16.136+02:00"},"s":"I",  "c":"STORAGE",  "id":4615611, "ctx":"initandlisten","msg":"MongoDB starting","attr":{"pid":2944,"port":27018,"dbPath":"/data/db","architecture":"64-bit","host":"MacBook-Pro-de-Gaetan.local"}}
{"t":{"$date":"2020-09-07T12:18:16.136+02:00"},"s":"I",  "c":"CONTROL",  "id":23403,   "ctx":"initandlisten","msg":"Build Info","attr":{"buildInfo":{"version":"4.4.0","gitVersion":"563487e100c4215e2dce98d0af2a6a5a2d67c5cf","modules":["enterprise"],"allocator":"system","environment":{"distarch":"x86_64","target_arch":"x86_64"}}}}
{"t":{"$date":"2020-09-07T12:18:16.136+02:00"},"s":"I",  "c":"CONTROL",  "id":51765,   "ctx":"initandlisten","msg":"Operating System","attr":{"os":{"name":"Mac OS X","version":"19.6.0"}}}
{"t":{"$date":"2020-09-07T12:18:16.136+02:00"},"s":"I",  "c":"CONTROL",  "id":21951,   "ctx":"initandlisten","msg":"Options set by command line","attr":{"options":{"net":{"port":27018}}}}
{"t":{"$date":"2020-09-07T12:18:16.137+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-09-07T12:18:16.137+02:00"},"s":"I",  "c":"NETWORK",  "id":20562,   "ctx":"initandlisten","msg":"Shutdown: going to close listening sockets"}
{"t":{"$date":"2020-09-07T12:18:16.137+02:00"},"s":"I",  "c":"-",        "id":20520,   "ctx":"initandlisten","msg":"Stopping further Flow Control ticket acquisitions."}
{"t":{"$date":"2020-09-07T12:18:16.137+02:00"},"s":"I",  "c":"CONTROL",  "id":20565,   "ctx":"initandlisten","msg":"Now exiting"}
{"t":{"$date":"2020-09-07T12:18:16.137+02:00"},"s":"I",  "c":"CONTROL",  "id":23138,   "ctx":"initandlisten","msg":"Shutting down","attr":{"exitCode":100}}

Plus, it's not running anywhere :

gaetan@MacBook-Pro-de-Gaetan ~ % sudo killall mongod
Password:
No matching processes were found
gaetan@MacBook-Pro-de-Gaetan ~ % sudo killall mongo 
No matching processes were found
gaetan@MacBook-Pro-de-Gaetan ~ % sudo killall mongodb
No matching processes were found
gaetan@MacBook-Pro-de-Gaetan ~ % 
  • try another port – Hasan Tareque Sep 07 '20 at 10:18
  • The problem comes from : "Failed to unlink socket file". And since `mongod` doesn't work. The mongo service can't start, and you cant connect to it with node.js. Maybe this could help : https://stackoverflow.com/questions/29813648/failed-to-unlink-socket-file-error-in-mongodb-3-0 – AlexisG Sep 07 '20 at 10:18
  • I didn't worked either. Plus I didn't understood half the things they said, I'm new at this. – Gaëtan CHABOUSSIE Sep 07 '20 at 12:25

3 Answers3

0

Try creating a new 'db' and 'log' directory in the data directory under the 'MongoDB' installation directory and a new 'mongo.log' file under the 'log' directory

0

Thanks for your answer. But i think something went wrong with the installation. A couple weeks ago, i formated my mac and reinstalled everything in a clean way using brew. Now, everything works fine. Thanks anyway

-1

You could give the solution here a shot. SocketException: Address already in use MONGODB

Since it's returning a socket error the mongodb default port could be in use by another service even when it's highly unlikely.

Victor Chris
  • 1
  • 1
  • 1