Loading product documents into MongoDB
A practical workshop for a catalogue service consumes product documents. Build the smallest manifest, validate it, run it and read the result.
Context — a catalogue service consumes product documents
The task is currently manual and its assumptions are not recorded. Hydra turns it into files that can be reviewed and rerun.
Where things stand
- The current result is fragile. Its assumptions are split between tools, clicks and memory.
- Reruns are uncertain. The write mode or orchestration rule is not visible beside the data.
- Evidence is missing. A colleague cannot compare a declared rule with a concrete before and after state.
The question
How do you load records into mongodb with explicit, testable rerun semantics?
- Keep credentials outside YAML
- Choose append, replace or upsert deliberately
- Validate before touching the target
- Verify the target after a second run
The solution in one line
A Hydra mongodb destination wired to a deterministic three-row fixture.
id,name,amount 1,Amina,120.5 2,Lucas,83.0 3,Sofia,49.9
Start from three known records.
Steps
1. prepare a deterministic input
- Start from three known records.
- Compare the file with the explanation in the workbench.
- Record the shown check before moving to the next step.
id,name,amount 1,Amina,120.5 2,Lucas,83.0 3,Sofia,49.9
2. declare the input
- Read the fixture as CSV.
- Compare the file with the explanation in the workbench.
- Record the shown check before moving to the next step.
version: "1.0"
sources:
input:
type: csv
connection:
base_path: "data"
extract:
table: input.csv 3. declare the mongodb destination
- Describe the target and write mode.
- Compare the file with the explanation in the workbench.
- Record the shown check before moving to the next step.
version: "1.0"
destinations:
target:
type: mongodb
connection:
uri: ${ENV:MONGODB_URI}
database: catalogue
load:
collection: products
mode: upsert
key: [sku] 4. wire the load
- Connect input to target.
- Compare the file with the explanation in the workbench.
- Record the shown check before moving to the next step.
version: "1.0" pipeline: from: input to: target
5. validate the manifest
- Catch shape and identifier mistakes.
- Compare the file with the explanation in the workbench.
- Record the shown check before moving to the next step.
$ hdrctl test mongodb-destination ok sources.yaml — csv ok destinations.yaml — mongodb ok pipeline.yaml — input → target ✅ All tests pass — ready to execute.
6. run and inspect the target
- Execute once, then verify rows and mode.
- Compare the file with the explanation in the workbench.
- Record the shown check before moving to the next step.
$ hdrctl run mongodb-destination
✅ Pipeline completed successfully
Rows read : 3
Rows written: 3
{"sku":"SKU-10","name":"Desk lamp","price":39.9}
{"sku":"SKU-11","name":"Chair","price":129.0} Expected result
- Three rows reach the target.
- The chosen mode defines the second run.
- Credentials remain outside the manifest.
Reading the results
Rows written is the connector acceptance count. Confirm the physical target as well: files, tables, collections and APIs can impose constraints beyond the DSL.
What the counters do—and do not—prove
They prove how many records entered and left this run. They do not replace checking the target schema, the business meaning of values or the reason a workflow step was skipped.
The rule to carry forward
For repeatable loads, make the upsert key unique in the collection.
Did we answer the question?
| objective | result | where |
|---|---|---|
| Configuration explicit | yes | the relevant YAML block |
| Safe rerun | yes | the destination or workflow policy |
| Observable result | yes | the command output and counters |
| Hidden manual rule | removed | the rule now lives in versioned text |
Before and after
- Before — a catalogue service consumes product documents requires a person to remember the order, options and checks.
- After — one reviewed manifest and one command produce the same observable result.
- What is really gained — The durable gain is the contract: a colleague can read the configuration, reproduce the run and challenge the assumptions.