Troubleshooting MongoDB Private Endpoint Connection Timeouts
When using MongoDB Atlas with AWS PrivateLink, you may encounter connection timeouts even when credentials and network access are correctly configured. This is often due to port restrictions in the PrivateLink connection. Common Symptoms You may see timeout errors similar to this when attempting to connect: ServerSelectionTimeoutError: No replica set members found yet, Timeout: 30s Resolution MongoDB Atlas requires a range of ports to be open for PrivateLink connections. To resolve connection timeouts: Ensure ports 1024-1074 are whitelisted in your security group configurations for the PrivateLink endpoint MongoDB PrivateLink uses dynamic ports in the range of 1024-65535, with PrivateLink typically using the first 50 ports by default When using the MongoDB connection string with PrivateLink, ensure you're using the correct endpoint format (typically includes '-pl-0' in the hostname) Note: If you're able to connect through MongoDB Compass but not through direct connection strings, verify that you're using the correct PrivateLink-enabled hostname in your connection string. Alternative Connection Method If you need temporary access while configuring PrivateLink, you can: Whitelist your NAT Gateway IP (additional costs may apply) Use the standard MongoDB Atlas connection string (without the '-pl-0' suffix) For production environments, it's recommended to properly configure PrivateLink with the appropriate port ranges rather than relying on NAT Gateway access.
Last updated
Was this helpful?

