Skip to main content

moss-connector-mongodb

MongoDB source connector for Moss. Self-contained, no separate core package to install.

Install

pip install moss-connector-mongodb

Pulls pymongo as a dependency.

Usage

import asyncio
from moss import DocumentInfo
from moss_connector_mongodb import MongoDBConnector, ingest

async def main():
    source = MongoDBConnector(
        uri="mongodb://localhost:27017",
        database="shop",
        collection="articles",
        mapper=lambda r: DocumentInfo(
            id=str(r["_id"]),
            text=r["body"],
            metadata={"title": r["title"]},
        ),
        filter={"status": "published"},                # optional
        projection={"_id": 1, "title": 1, "body": 1},  # optional
    )

    result = await ingest(
        source,
        project_id="your_project_id",
        project_key="your_project_key",
        index_name="articles",
    )
    print(f"copied {result.doc_count} rows")

asyncio.run(main())

Use auto_id=True when your mapper does not have a stable primary key and you want Moss to generate UUID document IDs.

MongoDB's _id is a bson.ObjectId. Wrap it with str() in your mapper to render the hex string.

Layout

src/
├── __init__.py      # re-exports MongoDBConnector and ingest
├── connector.py     # MongoDBConnector class
└── ingest.py        # ingest() - keep in sync with the other connector packages

Tests

pip install -e ".[dev]"
pytest tests/test_mongodb.py -v                       # mocked Moss + mocked Mongo
pytest tests/test_integration_mongodb_moss.py -v -s   # live Moss + local Mongo

The live integration test expects a Mongo at mongodb://localhost:27017 - edit MONGODB_URI at the top of the test file to change.

Metadata

Release files for moss-connector-mongodb 0.0.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for moss-connector-mongodb 0.0.1
File Size Uploaded
moss_connector_mongodb-0.0.1.tar.gz 6.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for moss-connector-mongodb 0.0.1
File Interpreter ABI Platform
moss_connector_mongodb-0.0.1-py3-none-any.whl Python 3 none any Details

Total release size: 10.8 kB

Release files / moss_connector_mongodb-0.0.1.tar.gz

Download URL moss_connector_mongodb-0.0.1.tar.gz
Size 6.6 kB
Tags Source
SHA-256 checksum
How to use checksums
aeb8d3f7490de819ee4710f5bcea3229752410aebd0828e7317bc847bd525893
BLAKE2b-256 checksum
How to use checksums
56617ad8c2974885649652e2978dec4d92402de43ef5eed19aab977efefc7c93
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release files / moss_connector_mongodb-0.0.1-py3-none-any.whl

Download URL moss_connector_mongodb-0.0.1-py3-none-any.whl
Size 4.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0ee68d3cbe410fe2425d80e37350148b8c8ab8b40b69a370ef01f659d895c42b
BLAKE2b-256 checksum
How to use checksums
23bff7b66a9d5717b12f87990e3f6072fc0925fb33c41742139583c5faeb8008
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.15

Release history Release notifications | RSS feed

This release

0.0.1 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page