If your website or application is unable to connect to MongoDB, the issue is often related to IP access restrictions or incorrect connection settings.
Common Cause
Most MongoDB servers, especially managed services like MongoDB Atlas, block all external IP addresses by default. This means your hosting server’s IP must be explicitly allowed to access the database.
Here’s how to fix it:
STEP 1: Whitelist Your Server IP
- Log in to your MongoDB server or managed database provider (e.g., MongoDB Atlas).
- Add your hosting server’s IP address to the IP Access List.
- Save and apply the changes.
STEP 2: Verify Connection String and Credentials
- Ensure your connection string (URI) includes the correct host, port, database name, username, and password.
- Double-check for any typos or missing parameters.
STEP 3: Retry the Connection
- After updating your access settings, try reconnecting your website or application to the database.
NOTE:
- If your hosting IP changes frequently (common on shared hosting), consider using a static IP or VPN with a fixed address.
- For added security, avoid using 0.0.0.0/0 (allow all IPs) unless absolutely necessary.
If you’re unsure of your hosting server’s IP address or need help configuring the connection, kindly reach out to LyteHosting Support for assistance.