Skip to content

API Reference parrot.tools.dataset_manager.sources.mongo

github-actions[bot] edited this page Dec 2, 2026 · 4 revisions

parrot.tools.dataset_manager.sources.mongo

View source

MongoSource — DataSource subclass for MongoDB/DocumentDB collections.

Read-only. Every fetch() call MUST include a filter dict parameter — no full-collection scans are allowed. A projection dict is also required to limit returned fields.

On registration, prefetch_schema() runs a find_one() on the collection to infer field names and types from a single document (excluding the internal _id field).

Credential resolution supports either a DSN (MongoDB connection string) or a credentials dict with host/port/user/password/database keys.

Alias DataSource

Re-exported from parrot.tools.dataset_manager.sources.base.DataSource.

Class MongoSource

DataSource for MongoDB/DocumentDB collections via asyncdb's mongo driver.

Read-only. Every fetch() call requires both a filter dict and a projection dict to prevent full-collection scans and limit the fields returned.

prefetch_schema() calls find_one() on the collection to infer field names and Python types from a single document.

Parameter Type Default Description
collection str MongoDB collection name, e.g. "orders".
name str Dataset name/identifier for this source.
database str MongoDB database name, e.g. "mydb".
credentials Optional[Dict[str, Any]] None Optional credentials dict with host/port/user/password. Used when dsn is None.
dsn Optional[str] None Optional MongoDB connection string (DSN). Takes priority over the credentials dict.
required_filter bool True If True (default), fetch() raises ValueError when no filter is provided. Set False to allow unrestricted queries (not recommended for production).

Attributes:

Attribute Type Description
cache_key str Stable Redis cache key for this MongoDB source. Format: mongo:{database}:{collection}

Method MongoSource.prefetch_schema

Infer schema from a single MongoDB document via find_one().

Excludes the internal _id field. The result is stored in self._schema and returned.

prefetch_schema() -> Dict[str, str]

Returns: Dict[str, str] — Dict mapping field_name → Python type name.

Raises:

  • RuntimeError — If the collection is empty or the driver fails.

Method MongoSource.fetch

Query the MongoDB collection and return a DataFrame.

Both filter and projection are required parameters.

fetch(**params) -> pd.DataFrame

Parameter Type Default Description
**params {} filter (dict): MongoDB query filter, e.g. {"status": "active", "amount": {"$gt": 100}}. Required when required_filter=True (default). projection (dict): MongoDB projection to limit returned fields, e.g. {"order_id": 1, "amount": 1, "_id": 0}. Always required.

Returns: pd.DataFrame — DataFrame built from the matching documents.

Raises:

  • ValueError — If filter is missing (when required_filter=True) or if projection is missing.
  • RuntimeError — If the driver query fails.

Method MongoSource.describe

Return a human-readable description for the LLM guide.

describe() -> str

Returns: str — String describing the MongoDB collection, database, and field count.

Alias lazy_import

Re-exported from parrot._imports.lazy_import.

Attribute logger

Architecture

Clients

Bots & Agents

Memory

Knowledge

Tools & Toolkits

Flows

Experts

Skills

Stores & Loaders

MCP & A2A

Server & APIs

Integrations

Outputs & A2UI

Prompts

Security

Operations

Migration

SDD Tooling

LLM Wiki

Deployment

Decisions

API Reference

Clone this wiki locally