--- title: MongoDB icon: database description: Set up the MongoDB resource in Python. --- ## Dependencies ```bash uv add pymongo ``` The `pymongo` package provides async MongoDB driver support via `AsyncMongoClient`. For credential setup, see the [MongoDB Setup](/home/setup/mongodb) guide. ## Configuration ### Mount all databases ```python import os from mirage import Workspace, MountMode from mirage.resource.mongodb import MongoDBConfig, MongoDBResource config = MongoDBConfig(uri=os.environ["MONGODB_URI"]) resource = MongoDBResource(config=config) ws = Workspace({"/mongodb/": resource}, mode=MountMode.READ) ``` ### Mount specific databases ```python config = MongoDBConfig( uri=os.environ["MONGODB_URI"], databases=["sample_mflix", "sample_analytics"], ) resource = MongoDBResource(config=config) ws = Workspace({"/mongodb/": resource}, mode=MountMode.READ) ``` The database directory always appears in the path, even when `databases` filters to a single entry. The full layout is documented under [MongoDB Resource](/python/resource/mongodb). ## Config Reference | Field | Required | Description | | ----------- | -------- | ------------------------------------------ | | `uri` | Yes | MongoDB connection URI | | `databases` | No | List of database names (omit to mount all) |