Connect to mongodb in linux

i have installed mongodb on linux (ubuntu) . but can’t connect to mongodb.

when i try mongo get this message :

MongoDB shell version v4.4.9
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:374:17
@(connect):2:6
exception: connect failed
exiting with code 1

when test using telnet :
telnet localhost 27017

i get this output :

Trying 127.0.0.1…
telnet: Unable to connect to remote host: Connection refused

Please help me .Thanks

Hello @Mor_Ka, welcome to the MongoDB Community forum!

You need to start the MongoDB server before you can connect and insert/query data. Have you started the mongod?

Also see Troubleshooting MongoDB Ubuntu Installation.

1 Like

Hi
Thanks for your Reply.
when i test this

mongod

command get a long output but it dose not make any difference .

output:

{“t”:{“$date”:“2021-10-15T12:33:23.325+03:30”},“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”:“2021-10-15T12:33:23.339+03:30”},“s”:“W”, “c”:“ASIO”, “id”:22601, “ctx”:“main”,“msg”:“No TransportLayer configured during NetworkInterface startup”}
{“t”:{“$date”:“2021-10-15T12:33:23.340+03:30”},“s”:“I”, “c”:“NETWORK”, “id”:4648601, “ctx”:“main”,“msg”:“Implicit TCP FastOpen unavailable. If TCP FastOpen is required, set tcpFastOpenServer, tcpFastOpenClient, and tcpFastOpenQueueSize.”}
{“t”:{“$date”:“2021-10-15T12:33:23.352+03:30”},“s”:“I”, “c”:“STORAGE”, “id”:4615611, “ctx”:“initandlisten”,“msg”:“MongoDB starting”,“attr”:{“pid”:2273,“port”:27017,“dbPath”:“/data/db”,“architecture”:“64-bit”,“host”:“morteza-Lenovo-3000-N500”}}
{“t”:{“$date”:“2021-10-15T12:33:23.352+03:30”},“s”:“I”, “c”:“CONTROL”, “id”:23403, “ctx”:“initandlisten”,“msg”:“Build Info”,“attr”:{“buildInfo”:{“version”:“4.4.9”,“gitVersion”:“b4048e19814bfebac717cf5a880076aa69aba481”,“openSSLVersion”:“OpenSSL 1.1.1f 31 Mar 2020”,“modules”:,“allocator”:“tcmalloc”,“environment”:{“distmod”:“ubuntu2004”,“distarch”:“x86_64”,“target_arch”:“x86_64”}}}}
{“t”:{“$date”:“2021-10-15T12:33:23.352+03:30”},“s”:“I”, “c”:“CONTROL”, “id”:51765, “ctx”:“initandlisten”,“msg”:“Operating System”,“attr”:{“os”:{“name”:“LinuxMint”,“version”:“20”}}}
{“t”:{“$date”:“2021-10-15T12:33:23.352+03:30”},“s”:“I”, “c”:“CONTROL”, “id”:21951, “ctx”:“initandlisten”,“msg”:“Options set by command line”,“attr”:{“options”:{}}}
{“t”:{“$date”:“2021-10-15T12:33:23.353+03:30”},“s”:“E”, “c”:“NETWORK”, “id”:23024, “ctx”:“initandlisten”,“msg”:“Failed to unlink socket file”,“attr”:{“path”:“/tmp/mongodb-27017.sock”,“error”:“Operation not permitted”}}
{“t”:{“$date”:“2021-10-15T12:33:23.353+03:30”},“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”:“2021-10-15T12:33:23.353+03:30”},“s”:“F”, “c”:“-”, “id”:23092, “ctx”:“initandlisten”,“msg”:“\n\n***aborting after fassert() failure\n\n”}

unfortunately your link

Troubleshooting MongoDB Ubuntu Installation.

dose not have any href and is only a text.
i appreciate if you send link for me .Thanks

Here is the corrected link:

The link is with the MongoDB Manual. And, you will also find proper instructions to start the mongod.

The output you are seeing is the server log; you can direct the log info to a log-file and also specify a folder where database data can be stored. These are specified as options while starting the mongod.

What is the version of Ubuntu Linux you are working with?

1 Like

Hello @Mor_Ka, I see from the logs that you are trying to install MongoDB on the Linux Mint: {“os”:{“name”:“LinuxMint”,“version”:“20”}}.

Also, there is an error in the log:
{“t”:{"$date":“2021-10-15T12:33:23.353+03:30”},“s”:“E”, “c”:“NETWORK”, “id”:23024, “ctx”:“initandlisten”,“msg”:“Failed to unlink socket file”,“attr”:{“path”:"/tmp/mongodb-27017.sock",“error”:“Operation not permitted”}}

There are some suggested solutions when you search online (Google search for mongodb install “path”:"/tmp/mongodb-27017.sock",“error”:“Operation not permitted”). You can try and see if it helps.

Also see this post with similar error in the server log:

1 Like

Hi @Prasad_Saya
Thank you for your advice and help :heart_eyes:

but unfortunately i cant start and use MongoDB .

when i get status the MongoDB serve is active :

sudo service mongodb status

● mongodb.service - MongoDB Database Service
Loaded: loaded (/lib/systemd/system/mongodb.service; enabled; vendor preset: enabled)
Active: active (exited) since Fri 2021-10-15 12:31:32 +0330; 1h 17min ago
Tasks: 0 (limit: 4566)
Memory: 0B
CGroup: /system.slice/mongodb.service
اكتبر 15 12:31:31 morteza-Lenovo-3000-N500 systemd[1]: Starting LSB: An object/document-oriented database…
اكتبر 15 12:31:31 morteza-Lenovo-3000-N500 mongodb[1165]: * Starting database mongodb
اكتبر 15 12:31:32 morteza-Lenovo-3000-N500 mongodb[1165]: …done.
اكتبر 15 12:31:32 morteza-Lenovo-3000-N500 systemd[1]: Started LSB: An object/document-oriented database.

@Mor_Ka,

If the service is already started, you can try to connect form mongo shell.
If you are not able to connect and there are errors, try stopping the service and restart the server / service and try to connect.

And, check the server logs if there are any errors.

1 Like