Skip to content

Infisical is the open-source platform for securing secrets, certificates, access, and AI Agents.

2.6 KB
Raw Blame
---
title: "MongoDB accounts"
sidebarTitle: "MongoDB"
description: "Give people and agents access to a MongoDB database without sharing its credentials."
---

A MongoDB [account](/documentation/platform/pam/accounts/overview) stores the credentials for one MongoDB user. Members connect to the database through the Infisical CLI, and Infisical records every command they run.

## Prerequisites

- The Admin [role](/documentation/platform/pam/concepts/access-control) on the [folder](/documentation/platform/pam/folders/overview) you'll add the account to
- A [gateway](/documentation/platform/gateways/overview) that can reach the database
- A MongoDB [account template](/documentation/platform/pam/templates/overview)

## Create the account

<Steps>
  <Step>
    Go to **Privileged Access Management** > **Accounts** and select **Add Account**.
  </Step>
  <Step>
    Select the **Folder** and a MongoDB **Account Template**, then select **Next**.
  </Step>
  <Step>
    Enter a **Name** and the connection details:

    | Field | Description |
    | --- | --- |
    | **Connection String** | The database's `mongodb://` or `mongodb+srv://` URI, without a username, password, or database, such as `mongodb+srv://cluster.example.com` |
    | **Database** | The database that sessions connect to (defaults to `admin`) |
    | **SSL Enabled** | Whether to connect over TLS |
    | **Reject Unauthorized** | Whether to reject a server certificate that can't be verified (shown when **SSL Enabled** is on) |
    | **SSL Certificate** | The CA certificate that signed the server's certificate (shown when **SSL Enabled** is on) |
  </Step>
  <Step>
    Enter the **Username** and **Password** of the MongoDB user, then select **Create**.
  </Step>
</Steps>

## Connect

To open a session, follow [Connect to an account](/documentation/platform/pam/accounts/connect). MongoDB accounts don't support the browser, so use the CLI.

Start the local proxy:

```bash
infisical pam access backend-team/users-db
```

The proxy keeps running in that terminal and prints its port. In a second terminal, connect your MongoDB client, such as `mongosh`, to that port:

```bash
mongosh "mongodb://localhost:<port>/users"
```

The proxy signs in for you, so the client doesn't need a password.

## Next steps

<CardGroup cols={2}>
  <Card title="Sessions" icon="monitor" href="/documentation/platform/pam/sessions/overview">
    Review and end the connections that people and agents make to your accounts.
  </Card>
  <Card title="Access requests" icon="hand" href="/documentation/platform/pam/access-requests/overview">
    Require approval before a member can use a sensitive account.
  </Card>
</CardGroup>