0

I am connecting to the mongodb database running locally on ec2 instance via ssh by using ssh identity file provided by aws. I have provided all the necessary fields while connecting to the remote database running on aws ec2 server locally. But it is connecting to my local database running on my local machine.I have provided an image below.

Please click here to see connection configuration

In this in the Hostname section i have provided below information hostname : localhost port : 27107 In the More Options section i have provided below information SSH Tunnel : selected Identity file SSH Hostname : given ip address of ec2 instance SSH Tunnel Port : 22 SSH Username : username of the server SSH Identity File : selected the ppk file given by aws

by using this details if i use to click connect then it is connecting to my local database running on my local machine.

Can anyone please help me with this.

Dhananjaya
  • 33
  • 8

1 Answers1

0

Only 1 process can listen on a port any time. If you already have a mongod process listening no port 27017, the SSH process that is started to connect to ec2 will not be able to bind to that port.

When you try to connect via SSH, it is unable to listen on 27017 because mongod is already listening, so when Compass subsequently connection to port 27017 it connects to the local mongod.

To connect to the remote mongod process, either stop the local mongod so ssh can bind to port 27017, or use a different port for one of the services.

Joe
  • 25,000
  • 3
  • 22
  • 44
  • it was working very well previously but from 3 days back i was having this issue. If i stop the mongo service then my application will not be able to communicate with database as it is not running. How to resolve this?? – Dhananjaya May 12 '20 at 17:38
  • The ssh tunnel you are trying to use listens on 127.0.0.1:27017 _on your local machine_. If that port is not available because you are running a mongod server there, use a different port. – Joe May 12 '20 at 19:00