Reputation: 1
Why while I run the command mongod
on server everything is ok and when I close ssh session on putty I see such error.
Unable to connect to Database: Failed to connect to: localhost:27017: Connection refused
Upvotes: 0
Views: 503
Reputation: 47986
The issue here is that the mongo server is being run in the ssh session you are opening when you connect. You'll have to detach the mongo server from your session by using disown
or by using a utility such as tmux or screen. This will allow your mongo server process to keep running after you have disconnected your ssh session.
Alternatively, as was mentioned in a comment above, if you run your mongo server as a service, you'll be able to disconnect from the ssh session and still have your server process running.
Starting mongo as a service would look something like this -
sudo service mongod start
So to explain it simply, when you connect via ssh, you are provided a shell on the server to execute commands. The moment you disconnect from your ssh session, your mongo server exits because it has no shell to run on. The shell that it did have was closed when you exited your ssh session.
Upvotes: 1