Learn how to fix the “Failed to connect to MongoDB Atlas Cluster” error. Our MongoDB Support team is here to help you with your questions and concerns.
Failed to connect to MongoDB Atlas Cluster | Solution
If you’re experiencing connection issues with MongoDB Atlas, especially errors like `MongooseServerSelectionError`, our Experts have your back.
Many users have recently reported similar issues, even after correctly whitelisting IP addresses. This blog provides a step-by-step guide to help you troubleshoot and resolve the issue.
An Overview:
Quick Solution
First, try this quick solution to resolve the error:
- Switch to a different internet connection first (some networks have strict firewalls that block Atlas connections).
- Disconnect any VPNs or proxies you’re using.
- Verify the system’s date and time settings to ensure they are up-to-date.
If you’re facing general connection issues, you might also find our MongoDB connection timeout troubleshooting guide helpful.
If this does not resolve the error, follow the step-by-step guide below.
Step-by-Step Fix for MongoDB Atlas Connection Issues
- First, log in to MongoDB Atlas at this link.
- Then, go to Network Access in the left sidebar.
- If you see an existing IP address listed, click Delete to remove it.
- Otherwise, follow these steps:
- Click Add IP Address.
- Select Add Current IP Address or Allow Access from Anywhere (0.0.0.0/0).
- We can add a comment for reference. This is optional.
- Click Confirm.
- Wait for the status to change from “pending” to “active.”
- Now, head to the Database Access and verify the DB user exists. Reset the password if you don’t remember it.
- Then, go to Cluster > Browse Collections and make sure that the database name they are trying to connect to exists.
- Next, restart the server.
- Then, double-check the connection string.
Here is an example of a correct connection string:
mongodb+srv://userWithAccessToDB:password@bob-75xyz.mongodb.net/Database_Name?retryWrites=true&w=majority
Copy CodeReplace userWithAccessToDB, password, and Database_Name with corresponding credentials. Also, make sure the `+srv` part is present.
Additional Troubleshooting Tips
- If you’re using Mongoose version `8.7.0` or newer and facing connection problems, downgrade to version `8.5.2` with this command:
npm install mongoose@8.5.2
Copy Code - If you’re behind a strict firewall, log in to the router settings and lower the firewall security level slightly if it’s set to “high.”
- If you’re behind a NAT or VPN, Atlas might see a different IP than your local machine’s IP. So, find the public IP at this link. Then, use this IP when whitelisting, or simply allow access from anywhere for testing.
-
Encountering TLS errors like “TLSv1 alert internal error”? This might also block your MongoDB connection. Learn how to fix it here.
- If the server is in a VPC Private Subnet, check if it’s using a NAT Gateway. Whitelist the NAT Gateway’s IP address in Atlas instead of the server’s internal IP.
- If the internet connection uses proxies or certificates, try connecting through a different network.
- If you face issues while installing MongoDB using
dpkg
, we have a full guide on resolving MongoDB dpkg errors.
[Need assistance with a different issue? Our team is available 24/7.]
Conclusion
MongoDB Atlas connection issues can be due to several reasons like network settings, firewall configurations, incorrect database credentials, or even outdated system settings.
In brief, our Support Experts demonstrated how to fix “Failed to connect to MongoDB Atlas Cluster”.
0 Comments