Question

Cannot connect Droplet to MongoDB in VPC despite firewall rules and trusted sources

Hi, I’m encountering a MongooseServerSelectionError: Server selection timed out after 30000 ms when attempting to connect my server application (running on a Droplet) to a DigitalOcean managed MongoDB instance.

Here’s my setup:

  • Environment: Both the Droplet and the MongoDB instance are within the same VPC.
  • Firewall Configuration: I have an outbound rule on the Droplet’s firewall allowing TCP traffic on port 27017 to the VPC IP range.
  • MongoDB Trusted Sources: I have added the tag associated with my Droplet to the MongoDB instance’s trusted sources.
  • Connection String: I am using the VPC connection string provided by DigitalOcean in my Mongoose adapter.

The Issue:

Despite these configurations, the connection consistently fails with the MongooseServerSelectionError.

Observation:

The only scenario where the connection is successful is when I temporarily configure the Droplet’s outbound firewall rule for port 27017 to allow traffic to “All IPv4 Addresses”. This is not a desirable long-term solution.

Question:

Could someone please help me identify what I might be missing or misconfiguring that prevents the connection from working correctly within the VPC? What further troubleshooting steps can I take to resolve this issue and establish a secure connection using the VPC?

Any insights or suggestions would be greatly appreciated!

Thanks.


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

Become a contributor for community

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

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

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.