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

# Async MongoDB

> Persist Agno sessions and other data asynchronously in MongoDB.

`AsyncMongoDb` stores Agent, Team, and Workflow sessions, memories, knowledge, evaluations, and traces asynchronously in [MongoDB](https://www.mongodb.com/).

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

## Usage

Install the `pymongo` (4.9 or later, for the async client) and `openai` packages:

```shell theme={null}
uv pip install "pymongo>=4.9" openai
```

<Note>
  `motor` clients are also supported, but `motor` is deprecated. Use PyMongo's async client instead.
</Note>

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

db_url = "mongodb://mongoadmin:secret@localhost:27017"

db = AsyncMongoDb(db_url=db_url)
agent = Agent(db=db)
```

Use async methods such as `Agent.arun()` and `Agent.aprint_response()` with this database.

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

## Parameters

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