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

# MongoDB

> Instructions for connecting to a MongoDB replica set to share data.

<Steps>
  <Step title="Locate connection information">
    ### MongoDB CLI

    1. Connect to your **MongoDB node** using the **MongoDB CLI** as an **admin**.
    2. Execute the following query:

    ```text title="MongoDB Script" theme={null}
    db.adminCommand( { replSetGetStatus : 1 } ).members
    ```

    3. Make a note of the **host identifiers**.

    ### MongoDB Atlas

    1. Log in to your Atlas **dashboard**, click into the **Database** tab and click **Connect**.
    2. Under **Connect your application**, click into the **Drivers** option.
    3. In the following screen, make a note of the **host identifier** within your connection string. It can be found within the string that starts with `mongodb+srv` and the identifier is the URI after the `@`. E.g., `some-cluster.some-characters.mongodb.net`.
  </Step>

  <Step title="Allow database access">
    ### MondoDB CLI

    1. Connect to your MongoDB node using the MongoDB CLI as an admin.
    2. Execute the following script (with a `username` and `password`) to create a new user.

    ```text title="MongoDB Script" theme={null}
       use admin
       db.createUser({
         user: "<username>",
         pwd: "<password>",
         roles: [ {role: "read", db: "<database>"} ]
       })

    ```

    ### MongoDB Atlas

    1. Log in to your Atlas **dashboard**, click into the **Database Access** section of the **Security** options.
    2. Select **Add New Database User**. Choose the **Password** authentication method, and enter a `username` and `password` for the new user.
    3. In the **Database User Privileges** menu, select **Grant Specific User Privileges**. Within **Specific Privileges**, add the following: `read@<database>` (for each database you'd like to grant access to). Leave the **Collection** field blank.
    4. Click **Add User** to create the new user.
  </Step>

  <Step title="Setting up Network Access">
    If your MongoDB instance enforces IP Access restrictions, you'll need to allow access to a static IP.

    ### MongoDB CLI

    1. Connect to your MongoDB node using the MongoDB CLI as an admin.
    2. Execute the following script

    ```text title="MongoDB Script" theme={null}
    use admin
    atlas accessLists create "<static_ip_address>" --comment "Prequel data sharing platform static IP"
    ```

    ### MongoDB Atlas

    1. Log in to your Atlas **dashboard**, click into the **Network Access** section of the **Security** options.
    2. Select **Add IP Address**. In **Access List Entry** enter your Prequel deployment's static IP. [See here](/export/deployment/prequel-ips) for the list of static IPs by deployment.
    3. Add an optional comment (e.g., "Prequel data sharing platform") and click **Confirm**.
  </Step>

  <Step title="Connect to Prequel">
    Use the **host name**, **port**, and **database name** (as noted in **Step 1**) and the **username** and **password** (as configured in **Step 2**) to complete the connection.
  </Step>
</Steps>
