> ## 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

> Connect MongoDB to xpander and give agents its 18 actions: how to create the API key and connect it, and which actions to hold for approval.

<Badge color="blue">HTTP API connector</Badge>

An HTTP API described by an OpenAPI spec, not an MCP server. Calls go through xpander's function endpoint `https://functions.xpander.ai/mongo-db`, which fronts the MongoDB API, and carry an API key in the `x-mongodb-uri` header.

## What the skill can do

API connector: 18 actions, as they appear in the skill panel. 18 of them create, change or delete something in MongoDB; mark those under **These actions need approval** when you add the skill to an agent.

* **Document writing** (7): Mongo Dbdocument Writing Delete Many Documents By Filter, Mongo Dbdocument Writing Insert One Document By Collection, Mongo Dbdocument Writing Delete One Document By Filter, Mongo Dbdocument Writing Update Many Documents By Filter, Mongo Dbdocument Writing Insert Many Documents By Collection, Mongo Dbdocument Writing Replace One Document By Filter, Mongo Dbdocument Writing Update One Document By Filter
* **Collection inspection** (5): Mongo Dbcollection Catalog List Collections By Database Name, Mongo Dbdatabase Catalog Get Accessible Database Names, Mongo Dbcollection Inspection List Indexes By Collection, Mongo Dbcollection Inspection Get Collection Stats By Name, Mongo Dbcollection Inspection Sample Collection Schema By Size
* **Document querying** (3): Mongo Dbdocument Querying Count Documents By Filter, Mongo Dbdocument Querying Find Documents By Filter Options, Mongo Dbdocument Querying Find One Document By Filter
* **Aggregation analytics** (2): Mongo Dbdocument Querying Get Distinct Values By Field Filter, Mongo Dbaggregation Analytics Run Aggregation Pipeline Collection
* **Connection validation** (1): Mongo Dbconnection Validation Validate Connection Ping Databases

## Authentication

The MongoDB skill currently supports **API Key authentication only** in xpander.

### 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.

### Connect MongoDB in xpander

1. In Xpander Chat, open the agent's settings and click **Add skill**.
2. Search for **MongoDB** and select it.
3. Click **Create new connection**.
4. Set **Connection name**.
5. Set **Connection access** (for example, `Personal`).
6. Select **API Key** as the authentication method.
7. In the API Key section, choose type **Custom**.
8. Set the custom header name to `x-mongodb-uri`.
9. Paste your MongoDB connection string as the header value.
10. Click **Connect**.

## Give an agent the MongoDB skill

Once MongoDB is connected, any agent you can edit may be given the skill: open the agent's settings, click **Add skill**, and choose **MongoDB**. The skill panel lists the MongoDB actions by group. Enable only the groups the agent needs, and mark the actions that should wait for a named person's sign-off under **These actions need approval**. Which skills exist for your organization, and who may add them, is decided by your admins; see [Skills](/use/skills).

### Available Operations

The MongoDB skill 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                             |

## Related Resources

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