> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.squarecloud.app/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# MongoDB Atlas whitelist (dynamic IP)

# MongoDB Atlas Whitelist on Square Cloud

Square Cloud uses dynamic IP allocation for its applications. This means your instance does not maintain a fixed IP between restarts, so MongoDB Atlas needs to allow connections more broadly.

---

## 1. The Dynamic IP Problem

When connecting a MongoDB Atlas database to your Square Cloud application, you might see this error:

```text
MongoNetworkError: connection 0 to shard-xxx-xxx.mongodb.net:27017 closed
```

This issue occurs because Atlas does not recognize your application's source IP, since it changes with every restart.

---

## 2. Why Does This Happen?

MongoDB Atlas requires you to add trusted source IPs to the whitelist. Since Square Cloud does not provide a static IP, it is not possible to add a single fixed address to Atlas.

---

## 3. How to Fix It

### Step-by-Step

1. Open the MongoDB Atlas dashboard.
2. Go to the Network Access / IP Access List section.
3. Add the address below:

```text
0.0.0.0/0
```

4. Save the changes.

### Security Note

Adding `0.0.0.0/0` opens the network so any IP can reach your cluster — so security now rests entirely on the authentication layers. Since you can't pin the IP on Square Cloud, offset it with these concrete mitigations:

* **Strong, unique password** for the database user (Atlas already enforces SCRAM authentication).
* **Always-on TLS/SSL** — Atlas forces the encrypted connection by default; don't disable it.
* **Least-privilege user:** create a dedicated user for the app with access only to the database it needs (avoid the admin role).
* **Credential rotation:** rotate the password periodically and whenever you suspect a leak; never commit the connection string to Git.

That way, even with the network open, no one reaches the database without the correct credentials.

---

## 4. Testing the Connection

After whitelisting on Atlas, try connecting your application again. If the error persists, check:

* Whether the database is active on Atlas.
* Whether the connection string is correct.
* Whether the application is using the right Atlas cluster.

![](https://storage.crisp.chat/users/helpdesk/website/-/d/a/4/9/da49f867735c6000/image_1th63g5.png)

---

## 5. What to Do If It Still Doesn't Work

* Confirm the cluster name and MongoDB Atlas user.
* Verify if the application is configured to connect to the correct port.
* If you use a VPC or additional rules on Atlas, adjust them accordingly.