Question

How to connect to a managed mongodb through VPN

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


Submit an answer


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!

Sign In or Sign Up to Answer

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.

Bobby Iliev
Site Moderator
Site Moderator badge
April 14, 2023
Accepted Answer

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

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Featured on Community

Get our biweekly newsletter

Sign up for Infrastructure as a Newsletter.

Hollie's Hub for Good

Working on improving health and education, reducing inequality, and spurring economic growth? We'd like to help.

Become a contributor

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

Welcome to the developer cloud

DigitalOcean makes it simple to launch in the cloud and scale up as you grow — whether you're running one virtual machine or ten thousand.

Learn more