MongoDbStorage class.
Usage
You need to provide eitherdb_url or client. The following example uses db_url.
mongodb_storage_for_agent.py
Params
Developer Resources
- View Cookbook
Documentation Index
Fetch the complete documentation index at: /llms.txt
Use this file to discover all available pages before exploring further.
You are viewing v1 docs. For the latest documentation, visit docs.agno.com
MongoDbStorage class.
db_url or client. The following example uses db_url.
from agno.storage.mongodb import MongoDbStorage
db_url = "mongodb://ai:ai@localhost:27017/agno"
# Create a storage backend using the Mongo database
storage = MongoDbStorage(
# store sessions in the agent_sessions collection
collection_name="agent_sessions",
db_url=db_url,
)
# Add storage to the Agent
agent = Agent(storage=storage)
| Parameter | Type | Default | Description |
|---|---|---|---|
collection_name | str | - | Name of the collection to be used. |
db_url | Optional[str] | None | Database URL, if provided. |
db_name | str | "agno" | Database Name. |
client | Optional[MongoClient] | None | MongoDB client, if provided. |
Was this page helpful?