Hi,
i have a problem to start the mongo Shell over the Terminal in Ubuntu 20.04.
i Have installed Mongodb like the description in the MongoDB Doc.
If i check the status with sudo systemctl status mongodb i can see the Active Status is active (running).
if i want to start the shell with mongo command in Terminal, so i get this Error:
MongoDB shell version v5.0.18
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:372:17
@(connect):2:6
exception: connect failed
exiting with code 1
i check the mongodb.conf to see where the log files from mongodb is saved.
The path is → logpath=/var/log/mongodb/mongodb.log
But in this path is not a file like mongodb.log. There are only a file mongod.lock, and in this file is only the number 6965. i think it is a processID.
And how can i check that mongod is up and accepting connections?
With service mongodb status, i can see the Status Active: active (running).
I have an external server with ubuntu 20.04. and i use Visual Studio Code to connect over the Terminal to the Server. Should i use the same port number, which i use to connect with ubuntu Server, or has nothing to do with it?
If your mongod is up you should be able to connect
Also mongod.log should be there
Are you checking the correct location?
If there are permission issues it’s possible mongod is not able to create logfile and terminating?
Did you try stop/start service?
1 - you have 2 machines
2 - you are running mongod on machine-1
3 - you are trying to connect with mongo on machine-2 using 127.0.0.1
Read about localhost to understand why it does not work.
Localhost or 127.0.0.1 refers to the same machine as you are running. So on machine-2, 127.0.0.1 is machine-2 and on machine-1, 127.0.0.1 is machine-1. From machine-2 you have to specify the host name or IP address of machine-1 in order to connect to mongod running on machine-1.
You’re right. It was my failure. The path to mongodb.log was wrong.
Inside the log file is:
2023-06-01T09:36:59.137+0000 I CONTROL [signalProcessingThread] got signal 15 (Terminated), will terminate after current cmd ends
2023-06-01T09:36:59.139+0000 I NETWORK [signalProcessingThread] shutdown: going to close listening sockets...
2023-06-01T09:36:59.139+0000 I NETWORK [signalProcessingThread] removing socket file: /tmp/mongodb-10000.sock
2023-06-01T09:36:59.142+0000 I FTDC [signalProcessingThread] Shutting down full-time diagnostic data capture
2023-06-01T09:36:59.145+0000 I STORAGE [signalProcessingThread] WiredTigerKVEngine shutting down
2023-06-01T09:36:59.215+0000 I STORAGE [signalProcessingThread] shutdown: removing fs lock...
2023-06-01T09:36:59.215+0000 I CONTROL [signalProcessingThread] now exiting
2023-06-01T09:36:59.215+0000 I CONTROL [signalProcessingThread] shutting down with code:0
I have also stop and start the service, but it doesn´t solve the problem.
I have connect over the terminal from Visual Studio Code with SSH to the external Server. So im on the shell from the external machine. I have installed mongodb over the npm Manager.
I know what localhost means.
Mongodb is installed on the same machine, where i have an ssh access to the shell.
if i check the status from mongodb with service mongodb status in the terminal i get:
.
.
Active: active (running) since Thu 2023-06-01 17:46:43 UTC; 2min 36s ago
.
.
That means that my mongodb is correctly installed an running. Right?
Normally i should be able start the mongo-shell with the command mongo. Right?
Maybe, i use the wrong command to start the mongo shell on the server. But in the examples on the internet explains, in order to start he shell, you scould use the command mongo
Thank you a lot. That was the problem.
With mongosh --port 10000 it was possible to start the Bash.
And yes the port number in the mongodb.conf, which is in the Path /etc/mongodb.conf, was set to PORT 10000.
I change it to the default Port number and now i can start the bash with mongosh.
I don’t know why the default port wasn’t set during installation, but now its work.