Problem with MongoDB Connection

Hey guys I have a MongoDB Atlas related question.

The situation comes here:

I have a shared cluster in Mongo Atlas and I can access it configuring SSH part in either Compass, Robo3T, NoSQLBooster but I’m not able to do it in code either node or python… And when I try to do it in the instance mongoshell I can’t either.

I have to note the following, the database mongodb+srv is accessible only from the EC2 instance BUT IT’S NOT located in the same one… its a mongo atlas, i have no admin so I can’t whitelist IP however, it comes to my mind HOW can I connect through clients but not my own code, any help?

I’m new, sorry if posted in the wrong section.

What error are you getting when run from shell?

Although, when i use the srv I can connect correctly, but I can’t do it through SSH… from my own app code.

Welcome to the MongoDB Community Forums @Sebastian_Bejarano !

What environment is your Node or Python application code running in?

  • If you have added an EC2 public IP to your Atlas IP Access List, your applications will be able to connect using valid credentials when running from the EC2 environment.

  • If your applications are running in another environment (for example, a desktop or laptop that you are using for development) you will need to add the relevant public IPs to your IP Access List.

I highly recommend one of the above methods for a straightforward (and well documented) solution.

If you are currently able to connect via desktop applications like Compass and SSH is involved I assume you are using an SSH Tunnel feature which routes application requests to Atlas via your EC2 instance. You may be able to set up something similar for your local apps, but would have to look into the SSH documentation to figure out how to set up an SSH tunnel using a client for your O/S. However, I wouldn’t recommend this path as it will involve some trial and error to set up and I expect will only work for direct connection to a single member of your Atlas replica set – all replica set members use the same port number, but you can only port forward a single local port to a single remote destination port.

Another alternative would be to set up a VPN connection to your EC2 instance, but you’ll have to find a relevant tutorial. VPN set up is not specific to MongoDB and is probably a better discussion to explore on Server Fault.


This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.