Skip to main content
Agno supports using MongoDB asynchronously, with the AsyncMongoDb class.
v2 Migration Support: If you’re upgrading from Agno v1, MongoDB is fully supported in the v2 migration script. See the migration guide for details.

Usage

Install the pymongo (4.9 or later, for the async client) and openai packages:
motor clients are also supported, but motor is deprecated. Use PyMongo’s async client instead.
async_mongodb_for_agent.py

Run MongoDB

Install docker desktop and run MongoDB on port 27017 using:

Params

ParameterTypeDefaultDescription
idOptional[str]-The ID of the database instance. UUID by default.
db_clientOptional[Union[AsyncIOMotorClient, AsyncMongoClient]]-The MongoDB async client to use. Supports Motor and PyMongo async clients.
db_nameOptional[str]-The name of the database to use.
db_urlOptional[str]-The database URL to connect to.
session_collectionOptional[str]-Name of the collection to store sessions.
memory_collectionOptional[str]-Name of the collection to store memories.
metrics_collectionOptional[str]-Name of the collection to store metrics.
eval_collectionOptional[str]-Name of the collection to store evaluation runs.
knowledge_collectionOptional[str]-Name of the collection to store knowledge documents.
culture_collectionOptional[str]-Name of the collection to store cultural knowledge.
traces_collectionOptional[str]-Name of the collection to store traces.
spans_collectionOptional[str]-Name of the collection to store spans.
learnings_collectionOptional[str]-Name of the collection to store learnings.
schedules_collectionOptional[str]-Name of the collection to store cron schedules.
schedule_runs_collectionOptional[str]-Name of the collection to store schedule run history.