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

# MongoDB Atlas

> Connect MongoDB Atlas to give OpenSRE visibility into cluster health, performance metrics, deployment status, and operational insights during incidents

## Overview

OpenSRE uses the **Atlas Admin API** (not a MongoDB connection string) to inspect cluster health, performance metrics, slow-query recommendations, and operational events when alerts fire.

For direct MongoDB wire-protocol diagnostics, see [MongoDB](/docs/integrations/databases/mongodb).

## Prerequisites

* MongoDB Atlas API Public Key
* MongoDB Atlas API Private Key
* Atlas Project ID
* Permissions to view cluster metrics and configuration (Project Read Only or higher)

## Setup

### Option 1: Interactive CLI

```bash theme={null}
opensre integrations setup mongodb_atlas
```

Enter your Atlas API credentials when prompted.

### Option 2: Environment variables

```bash theme={null}
MONGODB_ATLAS_PUBLIC_KEY=your_public_key
MONGODB_ATLAS_PRIVATE_KEY=your_private_key
MONGODB_ATLAS_PROJECT_ID=your_project_id
MONGODB_ATLAS_BASE_URL=https://cloud.mongodb.com/api/atlas/v2
```

| Variable                    | Default                                  | Description                            |
| --------------------------- | ---------------------------------------- | -------------------------------------- |
| `MONGODB_ATLAS_PUBLIC_KEY`  | —                                        | **Required.** Atlas API public key     |
| `MONGODB_ATLAS_PRIVATE_KEY` | —                                        | **Required.** Atlas API private key    |
| `MONGODB_ATLAS_PROJECT_ID`  | —                                        | **Required.** Atlas project identifier |
| `MONGODB_ATLAS_BASE_URL`    | `https://cloud.mongodb.com/api/atlas/v2` | Atlas Admin API base URL               |

### Option 3: Persistent store

```json theme={null}
{
  "version": 1,
  "integrations": [
    {
      "id": "mongodb-atlas-prod",
      "service": "mongodb_atlas",
      "status": "active",
      "credentials": {
        "public_key": "your_public_key",
        "private_key": "your_private_key",
        "project_id": "your_project_id"
      }
    }
  ]
}
```

## Credentials

1. Log in to MongoDB Atlas
2. Navigate to Access Manager → API Keys
3. Create a Project API Key
4. Copy the Public Key and Private Key
5. Copy the Project ID from Atlas project settings

<Info>
  This integration uses the **Atlas Admin API**, not a MongoDB connection string. Create a Project API key with read access to cluster metrics and alerts.
</Info>

## Tools

| Tool                                    | What it does                                             |
| --------------------------------------- | -------------------------------------------------------- |
| `get_mongodb_atlas_clusters`            | Clusters in the project — state, version, size, topology |
| `get_mongodb_atlas_cluster_metrics`     | CPU, disk I/O, connections, opcounters                   |
| `get_mongodb_atlas_alerts`              | Open Atlas alerts                                        |
| `get_mongodb_atlas_cluster_events`      | Recent project events (scaling, backups, maintenance)    |
| `get_mongodb_atlas_performance_advisor` | Slow-query / missing-index recommendations               |

## Verify

```bash theme={null}
opensre integrations verify mongodb_atlas
```

Expected output:

```
Service: mongodb_atlas
Status: passed
Detail: Connected to MongoDB Atlas project ...
```

## Troubleshooting

| Symptom                          | Fix                                                                                                |
| -------------------------------- | -------------------------------------------------------------------------------------------------- |
| **401 Unauthorized**             | Regenerate the API key pair. Confirm public and private keys are copied correctly.                 |
| **403 Forbidden**                | Grant the API key **Project Read Only** (or higher) for the target project.                        |
| **Invalid project ID**           | Copy the Project ID from Atlas project settings — not the cluster name or connection string.       |
| **Verify passes but tools fail** | Confirm `MONGODB_ATLAS_PROJECT_ID` matches the project that owns the clusters under investigation. |

## Security

* Create a **dedicated Atlas API key** for OpenSRE with the minimum project role required.
* Rotate API keys periodically and revoke unused keys.
* Never commit API keys to source control — use `.env` or the integration store.
