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

# MongoDB Async

> Insert knowledge and query it asynchronously with ainsert() and aprint_response() on MongoDB.

## Code

```python async_mongo_db.py theme={null}
import asyncio

from agno.agent import Agent
from agno.knowledge.knowledge import Knowledge
from agno.vectordb.mongodb import MongoVectorDb

mdb_connection_string = "mongodb://localhost:27017"

knowledge = Knowledge(
    vector_db=MongoVectorDb(
        collection_name="recipes",
        db_url=mdb_connection_string,
    ),
)

agent = Agent(knowledge=knowledge)

if __name__ == "__main__":
    asyncio.run(
        knowledge.ainsert(
            url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf"
        )
    )

    asyncio.run(agent.aprint_response("How to make Thai curry?", markdown=True))
```

## Usage

<Snippet file="create-venv-step.mdx" />

**1. Install dependencies**

```bash theme={null}
uv pip install -U pymongo pypdf openai agno
```

**2. Run MongoDB**

```bash theme={null}
docker run -d \
--rm \
--name mongodb-container \
-p 27017:27017 \
-v ./tmp/mongo-data:/data/db \
mongodb/mongodb-atlas-local:8.0.3
```

**3. Set environment variables**

```bash theme={null}
export OPENAI_API_KEY=xxx
```

**4. Run Agent**

```bash theme={null}
python async_mongo_db.py
```


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.