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

# MongoDB

> Store agent sessions and run history in MongoDB with MongoDb.

`MongoDb` stores Agent sessions and run history in [MongoDB](https://www.mongodb.com/).

<Tip>
  The v1-to-v2 migration script supports MongoDB. See the [migration guide](/other/v2-migration).
</Tip>

## Usage

Install the `agno`, `pymongo`, and `openai` packages:

```shell theme={null}
uv pip install agno pymongo openai
```

### Run MongoDB

Install [Docker Desktop](https://docs.docker.com/get-started/get-docker/), then start MongoDB on port `27017`:

```bash theme={null}
docker run -d \
  --name local-mongo \
  -p 27017:27017 \
  -e MONGO_INITDB_ROOT_USERNAME=mongoadmin \
  -e MONGO_INITDB_ROOT_PASSWORD=secret \
  mongo
```

Pass either `db_url` or `db_client`. The default database name is `agno`; set `db_name` to use another database.

```python mongodb_for_agent.py theme={null}
from agno.agent import Agent
from agno.db.mongo import MongoDb

db_url = "mongodb://mongoadmin:secret@localhost:27017"
db = MongoDb(db_url=db_url)

agent = Agent(db=db)
```

## Parameters

<Snippet file="db-mongodb-params.mdx" />
