MongoDB source connector for moss-connectors.
Project description
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.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file moss_connector_mongodb-0.0.1.tar.gz.
File metadata
- Download URL: moss_connector_mongodb-0.0.1.tar.gz
- Upload date:
- Size: 6.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
aeb8d3f7490de819ee4710f5bcea3229752410aebd0828e7317bc847bd525893
|
|
| MD5 |
8fa145f6f06b473fd962c251abdbf7ca
|
|
| BLAKE2b-256 |
56617ad8c2974885649652e2978dec4d92402de43ef5eed19aab977efefc7c93
|
File details
Details for the file moss_connector_mongodb-0.0.1-py3-none-any.whl.
File metadata
- Download URL: moss_connector_mongodb-0.0.1-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.15
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ee68d3cbe410fe2425d80e37350148b8c8ab8b40b69a370ef01f659d895c42b
|
|
| MD5 |
94c47ecaf39430e45346d95ec94fcfab
|
|
| BLAKE2b-256 |
23bff7b66a9d5717b12f87990e3f6072fc0925fb33c41742139583c5faeb8008
|