Metadata-Version: 2.4
Name: moss-connector-mongodb
Version: 0.0.1
Summary: MongoDB source connector for moss-connectors.
Author-email: "InferEdge Inc." <contact@moss.dev>
License: BSD-2-Clause
Project-URL: Homepage, https://github.com/usemoss/moss
Project-URL: Repository, https://github.com/usemoss/moss
Project-URL: Source, https://github.com/usemoss/moss/tree/main/packages/moss-data-connector/moss-connector-mongodb
Keywords: moss,connectors,mongodb,mongo,ingest,etl
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: BSD License
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Topic :: Database
Requires-Python: <3.15,>=3.10
Description-Content-Type: text/markdown
Requires-Dist: moss>=1.1.1
Requires-Dist: pymongo>=4.6
Provides-Extra: dev
Requires-Dist: pytest>=8.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.23.0; extra == "dev"
Requires-Dist: python-dotenv>=1.0.0; extra == "dev"
Requires-Dist: ruff>=0.5.0; extra == "dev"

# moss-connector-mongodb

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

## Install

```bash
pip install moss-connector-mongodb
```

Pulls `pymongo` as a dependency.

## Usage

```python
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

```bash
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.
