mkpipe-loader-mongodb
MongoDB loader plugin for MkPipe. Writes Spark DataFrames into MongoDB collections using the official MongoDB Spark Connector.
Documentation
For more detailed documentation, please visit the GitHub repository.
License
This project is licensed under the Apache 2.0 License - see the LICENSE file for details.
Connection Configuration
connections:
mongo_target:
variant: mongodb
mongo_uri: 'mongodb://user:password@host:27017/mydb?authSource=admin'
database: mydb
Alternatively, use individual parameters (URI is constructed automatically):
connections:
mongo_target:
variant: mongodb
host: localhost
port: 27017
database: mydb
user: myuser
password: mypassword
Table Configuration
pipelines:
- name: pg_to_mongo
source: pg_source
destination: mongo_target
tables:
- name: public.events
target_name: stg_events
replication_method: full
Write Strategy
Control how data is written to MongoDB:
- name: public.events
target_name: stg_events
write_strategy: upsert # append | replace | upsert
write_key: [event_id] # required for upsert
| Strategy | MongoDB Behavior |
|---|---|
append |
Insert documents via Spark connector (default for incremental) |
replace |
Drop collection, then insert (default for full). With if_exists: append: delete all documents + insert (preserves collection/indexes) |
upsert |
Auto-creates a unique index on write_key columns, then writes with Spark connector operationType=replace matching on write_key |
Note:
upsertrequireswrite_key. The loader automatically creates a unique compound index on thewrite_keycolumns before writing. Existing documents matching the key are replaced; new documents are inserted.Migration: If you previously used
dedup_columnsfor implicit upsert behavior, switch to explicitwrite_strategy: upsertwithwrite_key. The old behavior still works but emits a deprecation warning.
Write Parallelism
By default Spark writes to MongoDB using however many partitions the DataFrame currently has. You can control write parallelism with write_partitions, which calls coalesce before the write to reduce the number of open connections to MongoDB:
- name: public.events
target_name: stg_events
replication_method: full
write_partitions: 4 # coalesce DataFrame to N partitions before writing
When to use write_partitions
- Reduce connections: MongoDB has a connection limit per node. If Spark has many executors, each partition opens its own connection. Lowering
write_partitionsreduces connection count. - Increase throughput: A small number of large batches is generally faster than many small batches. A value of 4–8 is a good starting point.
coalescevsrepartition:coalesceavoids a shuffle (preferred for write). If the source has very few partitions and you want to increase them, userepartition— but that requires a code-level change, not a YAML setting.
Performance Notes
- Write speed is mostly limited by MongoDB's write capacity and network, not Spark.
write_partitionsis most effective when reducing an already-large partition count.- For append-mode incremental loads the default partition count is usually fine.
All Table Parameters
| Parameter | Type | Default | Description |
|---|---|---|---|
name |
string | required | Source table/collection name |
target_name |
string | required | MongoDB destination collection name |
replication_method |
full / incremental |
full |
Replication strategy |
write_partitions |
int | — | Coalesce DataFrame to N partitions before writing |
batchsize |
int | 10000 |
Records per write batch |
write_strategy |
string | — | append, replace, upsert |
write_key |
list | — | Key columns for upsert (unique index created automatically) |
if_exists |
string | — | replace (drop+create) or append (preserve collection, delete+insert). Inherits from settings |
dedup_columns |
list | — | Columns used for mkpipe_id hash deduplication |
tags |
list | [] |
Tags for selective pipeline execution |
pass_on_error |
bool | false |
Skip table on error instead of failing |
Metadata
Release files for mkpipe-loader-mongodb 0.12.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| mkpipe_loader_mongodb-0.12.0.tar.gz | 12.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mkpipe_loader_mongodb-0.12.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 26.1 kB
Release files / mkpipe_loader_mongodb-0.12.0.tar.gz
| Download URL | mkpipe_loader_mongodb-0.12.0.tar.gz |
|---|---|
| Size | 12.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
5ec0f6bb7cdfe456682574d6c408741fe91bcdfb6a0f08c348aa7d55a1f07fb9
|
|
BLAKE2b-256 checksum How to use checksums |
b9ee91c0f894fb804a05bb435f8965ca869f958716bee208a8f65e51929f108a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Release files / mkpipe_loader_mongodb-0.12.0-py3-none-any.whl
| Download URL | mkpipe_loader_mongodb-0.12.0-py3-none-any.whl |
|---|---|
| Size | 13.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
4f97ff9734e9bb41c2697d4a51e853d6dafb354df3e9c671ac62174bbc9c499f
|
|
BLAKE2b-256 checksum How to use checksums |
99fa340a8de149490e3fe31bf4f54cf9842f114dd4c9925c8ada7b37d636ee7f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.11.15
|
Security for mkpipe-loader-mongodb 0.12.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.