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

# MongoDB Atlas

> Learn how to integrate AI agents with MongoDB Atlas using xpander.ai. Enable intelligent workflows that query, insert, update, and delete data across your MongoDB collections, run aggregation pipelines, and discover database schemas.

## About MongoDB Atlas

MongoDB Atlas is a fully managed cloud database service built on MongoDB — the most popular NoSQL document database. It provides a flexible, scalable, and developer-friendly platform for modern applications.

Key features include:

* **Document Model**: MongoDB stores data as flexible JSON-like documents, making it easy to model complex, hierarchical data structures without rigid schemas.

* **Multi-Cloud Deployment**: Atlas runs on AWS, Azure, and Google Cloud, offering global clusters, automated failover, and cross-region replication for high availability.

* **Full-Text Search**: Built-in Atlas Search powered by Apache Lucene enables rich text search capabilities directly on your MongoDB data without external search engines.

* **Aggregation Framework**: MongoDB's powerful aggregation pipeline supports complex data transformations, grouping, filtering, and analytics directly within the database.

* **Security & Compliance**: Atlas provides encryption at rest and in transit, network isolation, role-based access control, and compliance with SOC 2, HIPAA, PCI DSS, and GDPR.

* **Scalability**: From serverless instances for development to dedicated clusters handling millions of operations per second, Atlas scales with your needs.

## Authentication

The MongoDB Atlas connector currently supports **API Key authentication only** in xpander.ai.

### Supported method

* **Auth Method:** API Key
* **Header Name:** `x-mongodb-uri`
* **Header Value:** your full MongoDB connection string

Example value:

```text theme={"dark"}
mongodb+srv://<username>:<password>@cluster0.xxxxx.mongodb.net/
```

### MongoDB-side requirements

On the MongoDB side, use standard MongoDB **username/password** credentials in the connection string.

### Configure in xpander.ai

1. In xpander.ai, open **Connectors**.
2. Select **MongoDB Atlas** and click **Create new connection**.
3. Set **Connection name**.
4. Set **Connection access** (for example, `Personal`).
5. Select **API Key** as the authentication method.
6. In the API Key section, choose type **Custom**.
7. Set the custom header name to `x-mongodb-uri`.
8. Paste your MongoDB connection string as the header value.
9. Click **Save**.

<img src="https://mintcdn.com/xpanderai-099931d1/rXkqLg4uvj6qeYly/images/connectors/mongodb-atlas/img_1.png?fit=max&auto=format&n=rXkqLg4uvj6qeYly&q=85&s=dd1d551d2e15bcc39577584b0a1d587b" alt="MongoDB Atlas connection configuration" width="901" height="1036" data-path="images/connectors/mongodb-atlas/img_1.png" />

## Integration of MongoDB Atlas into AI Agent

Once you've configured your MongoDB Atlas connector with the authentication option(s) described above, you can integrate it into your AI agent with xpander.ai:

1. In your xpander.ai dashboard, go to the **Agent Configuration** tab and select **Tools**, then click **Add Tools**.
2. Select **Connectors**.
3. Choose **MongoDB Atlas** with the same **connector name** you configured in the previous section (e.g., xpander-mongodb).
4. Select the available MongoDB operations that suit your use case.

### Available Operations

The MongoDB Atlas connector provides the following operations:

**Discovery (Control Plane)**

| Operation                | Description                                                 |
| ------------------------ | ----------------------------------------------------------- |
| List Databases           | Returns all databases accessible by the configured user     |
| List Collections         | Returns all collection names in a specified database        |
| List Indexes             | Returns all indexes defined on a collection                 |
| Get Collection Stats     | Returns document count, storage size, and index information |
| Sample Collection Schema | Samples documents to detect field names and types           |

**Data Plane — Read**

| Operation                | Description                                                                  |
| ------------------------ | ---------------------------------------------------------------------------- |
| Find Documents           | Query with filter, projection, sort, limit, and skip                         |
| Find One Document        | Return the first document matching a filter                                  |
| Count Documents          | Count documents matching a filter                                            |
| Get Distinct Values      | Get unique values for a specific field                                       |
| Run Aggregation Pipeline | Execute MongoDB aggregation pipelines ($match, $group, $sort, $lookup, etc.) |

**Data Plane — Write**

| Operation             | Description                                               |
| --------------------- | --------------------------------------------------------- |
| Insert One Document   | Insert a single document                                  |
| Insert Many Documents | Batch insert multiple documents                           |
| Update One Document   | Update the first matching document using update operators |
| Update Many Documents | Update all matching documents                             |
| Replace One Document  | Replace an entire document                                |
| Delete One Document   | Delete the first matching document                        |
| Delete Many Documents | Delete all matching documents                             |

## AI Agent MongoDB Atlas Prompt Library

Below are possible prompts or use cases you can try after integrating MongoDB Atlas into your xpander AI agent:

```
What databases are available and how many collections does each one have?
```

```
Show me the schema of the {collection_name} collection in {database_name}.
```

```
Find all documents in {collection_name} where {field} is greater than {value}, sorted by {sort_field} descending.
```

```
What are the top 10 {category_field} values by document count in {collection_name}?
```

```
Insert a new document into {collection_name} with the following fields: {field1}: {value1}, {field2}: {value2}.
```

```
Update all documents in {collection_name} where {condition_field} equals {value} — set {update_field} to {new_value}.
```

```
Run an aggregation on {collection_name}: group by {field}, calculate the average {numeric_field}, and sort by the result.
```

```
How many documents in {collection_name} were created in the last 30 days?
```

## Related Resources

* [MongoDB Atlas Documentation](https://www.mongodb.com/docs/atlas/)
