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

# MongoDB

> Insert a PDF into a MongoDB collection and query it with an agent.

## Code

```python mongo_db.py theme={null}
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,
        search_index_name="recipes",
    ),
)

knowledge.insert(
    name="Recipes",
    url="https://agno-public.s3.amazonaws.com/recipes/ThaiRecipes.pdf",
    metadata={"doc_type": "recipe_book"},
)

# Create and use the agent
agent = Agent(knowledge=knowledge)
agent.print_response("How to make Thai curry?", markdown=True)
```

## Usage

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

  <Step title="Install dependencies">
    ```bash theme={null}
    uv pip install -U pymongo pypdf openai agno
    ```
  </Step>

  <Step title="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
    ```
  </Step>

  <Step title="Set environment variables">
    ```bash theme={null}
    export OPENAI_API_KEY=xxx
    ```
  </Step>

  <Step title="Run Agent">
    ```bash theme={null}
    python mongo_db.py
    ```
  </Step>
</Steps>
