Report this

What is the reason for this report?

How to connect to a managed mongodb through VPN

Posted on January 19, 2023

Hi there,

I created a managed mongodb to which I want to connect over my VPN which runs on another droplet in the same VPC. I use this VPN to connect from outside to other resources in the VPC. However, when I want to connect to the managed mongodb, that doesn’t work. I thought connection works when I add the IP range of the VPC to the trusted sources of the managed mongodb, and then use the ‘VPC network’ private hostname of the mongobd in the connection string, but that won’t work. Connection is only established when I add my computer’s IP address to the trusted sources but that’s a thing I would like to avoid.

Any hints?

Greetings Matthias



This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Hi there Matthias,

I believe that you would need to configure your VPN Droplet’s IP addresses to your MongoDB trusted sources.

You should be able to do this by:

  1. Ensure that your VPN Droplet and the managed MongoDB instance are in the same VPC and the VPN is properly configured to allow traffic between your local computer and the VPC resources.

  2. Add the VPN Droplet’s private IP address (the one in the VPC) to the trusted sources of the managed MongoDB instance. You can do this from the DigitalOcean Control Panel under the “Databases” tab, by clicking on your managed MongoDB instance and navigating to the “Settings” tab. Under “Trusted Sources,” click “Add Source” and enter the private IP address of your VPN droplet.

  3. Configure your VPN to forward traffic to the managed MongoDB instance. This may involve adding routing rules or configuring NAT on your VPN droplet, depending on your VPN setup. Here is a link to the documentation on how to setup that:

https://docs.digitalocean.com/products/networking/vpc/how-to/configure-droplet-as-gateway/

Let me know how it goes!

Best,

Bobby

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.