> ## Documentation Index
> Fetch the complete documentation index at: https://docs.usebracket.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Connecting MongoDB

> Follow these steps to sync an existing MongoDB collection

<Warning>MongoDB is currently in beta. Might be rough around the edges!</Warning>

## Optional: Adding Bracket as a user

<Note>Perform this step if you would like to give Bracket access through a dedicated account. Skip this step if you prefer to use an existing MongoDB account during setup.</Note>

1. Go to `Database Access`

<Example>
  <img class="rounded-md h-32" src="https://mintcdn.com/bracket/1whZePpi8DloDf7s/img/mongodb-1.png?fit=max&auto=format&n=1whZePpi8DloDf7s&q=85&s=23889903e8429df41bc37c09939156a8" width="370" height="294" data-path="img/mongodb-1.png" />
</Example>

2. Click `Add New User`

<Example>
  <img class="rounded-md w-full" src="https://mintcdn.com/bracket/1whZePpi8DloDf7s/img/mongodb-2.png?fit=max&auto=format&n=1whZePpi8DloDf7s&q=85&s=157e14d10f8ee9ceb8ac10cc46bd852f" width="2880" height="1528" data-path="img/mongodb-2.png" />
</Example>

3. Add a user with username `bracket` and an auto-generated password (blue box below). In the permissions section, select `Read and write to any database` in `Built-in roles` or define a custom role that allows read and write permission to the specific databases you want to connect with Bracket (red box below).

* If you assign a custom role for Bracket, at the minimum it must include read and/or write access for the specific collection that is being synced, depending on the direction of your sync.

4. Copy the username and password, which we'll use in the next step.

<Example>
  <img class="rounded-md w-full" src="https://mintcdn.com/bracket/1whZePpi8DloDf7s/img/mongodb-3.png?fit=max&auto=format&n=1whZePpi8DloDf7s&q=85&s=5247c59e0ea6631347bb9e790025ec08" width="796" height="1314" data-path="img/mongodb-3.png" />
</Example>

## Getting connection string URI

1. Go to the `Database Deployments` page in MongoDB by clicking `Database` on the left sidebar (see below).

<Example>
  <img class="rounded-md h-32" src="https://mintcdn.com/bracket/1whZePpi8DloDf7s/img/mongodb-6.png?fit=max&auto=format&n=1whZePpi8DloDf7s&q=85&s=909b28d00fe6e6e4a0f7cb2b66d2427f" width="374" height="144" data-path="img/mongodb-6.png" />
</Example>

2. Next to the name of the cluster you would like to connect with Bracket, click `Connect`.

<Example>
  <img class="rounded-md w-full" src="https://mintcdn.com/bracket/1whZePpi8DloDf7s/img/mongodb-7.png?fit=max&auto=format&n=1whZePpi8DloDf7s&q=85&s=5e0b2ab046ab48ea22c4318282e1abf0" width="1190" height="182" data-path="img/mongodb-7.png" />
</Example>

3. Then click `Connect your application`.

<Example>
  <img class="rounded-md w-full" src="https://mintcdn.com/bracket/1whZePpi8DloDf7s/img/mongodb-8.png?fit=max&auto=format&n=1whZePpi8DloDf7s&q=85&s=0acb7ed8b8e76590c1f9d6e1ec4ba3b5" width="1494" height="174" data-path="img/mongodb-8.png" />
</Example>

4. Copy the connection string provided, then replace `<username>` and `<password>` with the username and password created for Bracket in the previous step (or with the username and password for an existing MongoDB user). It should have the same format as this:

```shell MongoDB Connection URI theme={null}
mongodb+srv://<username>:<password>@cluster0.at2mo.mongodb.net/?retryWrites=true&w=majority
```

Enter the full URI in the webapp at app.usebracket.com.

## Whitelisting 0.0.0.0/0 IP address

Navigate to "Network Access" on the lefthand sidebar.

<Example>
  <img class="rounded-md h-32" src="https://mintcdn.com/bracket/1whZePpi8DloDf7s/img/mongodb-9.png?fit=max&auto=format&n=1whZePpi8DloDf7s&q=85&s=25f391a889fe3cc52ec8df1142aef715" width="358" height="204" data-path="img/mongodb-9.png" />
</Example>

1. Click "Add IP Address".

2. In the "Whitelist Entry" field, type in "0.0.0.0/0" The comment field is optional. Click "Confirm".

<Info>
  Note that whitelisting 0.0.0.0/0 as an IP address makes the database
  accessible from anywhere, but does not change the fact that access still
  requires a username and password generated by your database administrator.
  Alternatively, Bracket can provide a static IP address under the Enterprise plan.
</Info>
