MongoDB
Materialize MySQL snapshots and ongoing changes as application-ready operational state in a MongoDB target.
Connector profile
- Category
- Databases
- Guide maturity
- GAStable guide and configuration contract
- Role in this guide
- Target
- Capabilities
- Operational-state materializationData write
- Compatibility
- MongoDB 4.0+ · Standalone, replica sets, and sharded clusters
Before you begin
Connector availability
The MongoDB connector is registered automatically by the Quickstart script. On standalone or fresh server container deployments, the connector catalog starts empty. Confirm that MongoDB is registered before authoring connections:
connectors
register mongodbSee When registration is required.
Target
Grant write access only to the destination database. The current target path
does not require the clusterMonitor role.
use admin
db.createUser({
user: "tapstate",
pwd: "your_password",
roles: [
{ role: "readWrite", db: "your_database" }
]
})Create a connection
version: tapstate/v1
kind: source
id: operational_state
connector: mongodb
config:
isUri: true
uri: "mongodb://${MONGO_WRITER_USER}:${MONGO_WRITER_PASSWORD}@state-rs0-1:27017,state-rs0-2:27017/operational_state?replicaSet=state-rs0&authSource=admin"The target deliberately omits mode and tables. Create the pipeline after the
MySQL source and MongoDB target both exist:
version: tapstate/v1
kind: pipeline
id: orders_to_operational_state
source: orders_source
serve:
from: /.*/
sync:
- id: write_operational_state
source: operational_state
write_mode: upsert
ddl: failupsert writes a document by its key; append only inserts. Keep the DDL
policy at fail unless the destination workflow has been staging-tested for
the schema events it receives.
Validate the configuration
tapstate validate --workdir tapstate-workvalid: 3 resources in tapstate-workThe resource shape, references, and applicable catalog rules were accepted. Runtime availability was not checked.
invalid: orders_source.tap.yml:12:1 dsl.unknown-field
Unknown field 'unexpected' at unexpected.Use the filename, location, diagnostic code, and suggested fix to update the resource.
Next, run the connection in a non-production environment and confirm credentials, network access, permissions, and a representative read or write.
Validation does not require all connection fields, reject unknown connector
keys, resolve the URI, or contact MongoDB. A syntactically valid resource that
uses mongo.invalid can therefore pass validation.
To check the target, register the MongoDB connector JAR, apply the workspace, and run the test from an authenticated REPL:
tapstate -w tapstate-workconnect http://127.0.0.1:8080
login admin
register mongodb -o json
apply
test operational_state -o jsonOnly outcome: PASSED establishes that the connector accepted the supplied
endpoint and credentials. A placeholder or unreachable host should produce
outcome: FAILED or a coded connector test error; the exact checks and timeout
come from the registered connector. See Register and test connectors
for the full sequence.
Limitations
- Confirm that each materialized collection has a stable key for
upsert. - Test source inserts, updates, deletes, and key changes against representative nested documents before consumers rely on the target.
- Verify target write concern, index creation, schema evolution, and document size limits in the MongoDB version and topology you operate.
Reference
Connection settings
| Field | Required | Default | Description |
|---|---|---|---|
isUri | Yes | true | Use a MongoDB URI when true; use individual fields when false. |
uri | With isUri: true | — | Full MongoDB connection URI including credentials and options. |
host | With isUri: false | — | MongoDB host list or address. |
database | With individual fields | — | Database name. |
user | No | — | MongoDB user. |
password | No | — | MongoDB password. |
additionalString | No | — | Additional connection parameters. |
schemaLimit | No | 1024 | Maximum schema-field count used during discovery. |
ssl | No | false | Enable the documented SSL connection setting. |
sslKey | With ssl | — | Client key material. |
sslPass | No | — | Password for the client key. |
sslValidate | No | — | Validate the server certificate. |
sslCA | With certificate validation | — | CA certificate material. |
mongodbLoadSchemaSampleSize | No | 1000 | Documents sampled for schema discovery. |
Source read settings
When reading change-data-capture events from MongoDB as a pipeline source:
| Field | Required | Default | Description |
|---|---|---|---|
decodeThreads | No | 8 | Number of worker threads allocated for parallel CDC event decoding. |
decodeQueueSize | No | 32 | Maximum event queue capacity per decode worker thread. |
Tune decodeThreads upward on multi-core runtime hosts when reading from high-throughput MongoDB replica sets with heavy change volume. Increasing decodeQueueSize helps absorb bursty change events but increases heap usage.
Data compatibility
| Family | Supported baseline | Portable representation |
|---|---|---|
| Text and code | String, JavaScript, Symbol | UTF-8 string |
| Numeric | Double, Int32, Int64, Decimal128 | Number or stringified decimal |
| Composite | Document, Array | Nested map or array |
| Binary and identifiers | Binary, ObjectId | Base64-encoded string (Binary), 24-character hexadecimal string (ObjectId) |
| Date and time | Date, Timestamp | Millisecond instant (Date), epoch seconds instant (Timestamp) |
| Regular expressions | RegEx | Pattern string formatted as /pattern/flags |
| Other | Boolean, MinKey, MaxKey, Null | Boolean, literal representation, null |
In the current materialization paths:
- Relational
TIMESTAMP(3)andDATETIMEmap to BSONDatepreserving the UTC instant at millisecond precision; source time zone or offset formatting is not stored. - BSON
Timestampvalues are decoded using seconds since the Unix epoch. The intra-second counter used in internal change streams is not carried into standard date-time values. - Portable values serialize complex types into JSON-compatible shapes (
ObjectIdas hex,Binaryas Base64, andRegExas/pattern/flags).