MongoDB is a Verified Source, flattened into the Warehouse through dlt

The spec promises "selected NoSQL sources". We add exactly one, MongoDB, and only as a Source: it syncs through dlt (as Postgres does, ADR-0012) into the existing Postgres or DuckDB Warehouse, so Transforms, Checks, Branch Environments and Reverse Sync stay SQL and unchanged. Documents are flattened: nested fields become columns (customer__name), lists become child tables (orders__items), and a collection is listed under the same tables: key as any other table. v1 offers Full Refresh and Incremental Sync only; an Incremental collection must name its cursor field (there is no _id default, because _id orders inserts, not updates, and would silently miss edited documents). The connection is one Secret Reference holding the whole connection string, plus a database: field. The Assistant gets the same add-source, connection-test and list-tables tools as for Postgres. CI verifies one MongoDB version (8) in a container; the demo Project stays Postgres-only and Atlas is not promised.

Breaking Change for documents: a field seen with a new type is always a Breaking Change; a field missing from the documents read counts as dropped only on a Full Refresh, since an Incremental Sync reads only changed documents and cannot tell a dropped field from an untouched one; a field present in only some documents is never one.

When the shape is measured: a Mongo collection has no column list to read before loading, so the Sync reads and flattens the documents through dlt, compares the flattened shape with the baseline, and halts before writing anything; it sees every document it reads, not a sample. The reader is our own small pymongo feed handed to dlt, not a copy of dlt's verified Mongo source, which is not in the installed dlt package and would be code we maintain anyway.

Types: ObjectId loads as text, Decimal128 as decimal, dates as timestamp. A field that changes type gets a second column from dlt (e.g. price__v_text), reported as price retyped (bigint -> text); accepting it keeps both columns and the user's dbt model reconciles them; adops never rewrites Warehouse columns. Because Mongo apps often mix whole and decimal numbers in one field, a Pipeline can pin a field's type (columns: {price: decimal}).

Child tables: a list becomes a Child table keyed by parent _id plus list position, or by a key the Pipeline names (e.g. [_id, sku]), since positions shift when an item is removed from the middle of a list. When a parent document is synced again, all its Child table rows are replaced, so a removed item never lingers. Child-table fields follow the same Breaking Change rules, and a whole Child table missing on a Full Refresh counts as its columns dropped. Child tables get the key Checks (unique, not empty) and "rows written equal list items read"; they do not get "no row loss" or "row count matches the Source", which a normal cart edit would fail or which Mongo cannot measure.

Assistant discovery: to suggest a Pipeline, the Assistant reads the whole collection when it has under 100,000 documents, and otherwise a spread sample (500 oldest, 500 newest, 1,000 random) labelled as a sample. It reports how often each field appears and where its shape changes over time (old orders with address as text, new ones as an object), and suggests a pinned type or a dbt fix up front. This is a guide only; the Sync is the real check.

Shape guards: Child tables go 2 levels deep by default (orders → items → options), deeper lists stay JSON, and a table can set its own max_depth. A field that would add more than 200 new columns in one run (keys that are dates, ids or SKUs, e.g. scores: {"2024-01-01": 5, …}) stops the Sync before writing; on a table's first run, which has no baseline, the guard is instead at most 1,000 columns in total. Going over either limit needs an approval line committed through Git, like heavy: (wide: {reason: …, max_columns: 1400, max_new_columns: …}), which the Assistant asks before writing; adops validate refuses max_columns above Postgres's 1,600. Approval is needed only when a limit is exceeded, never for every first run, so approvals stay rare enough to be read. The Assistant spots such fields at setup and suggests pinning them to json. A value that does not fit its pinned type (price pinned to decimal holding "N/A") stops the Sync as a Breaking Change naming the document, since a pin is a promise, not a hint. Two field names that become the same column (userId and user_id) stop the Sync before writing; the Pipeline resolves it with rename:. Nothing is merged or numbered automatically.

Cursor: an Incremental collection gets an extra built-in Check that fails when documents lack the cursor field ("1,204 orders have no updated_at"), skippable only with a written reason. It counts through the cursor's index, so it is cheap exactly when Incremental itself is; the Assistant and adops validate --env warn when the cursor field has no index. adops never changes the Source, so adding the index is the user's call.

Keys and records: a main table's key is always _id; a business key gets a declared Check instead. An Accepted-change record for a Child table names it like any table (orders__items: qty retyped (bigint -> text)).

Collection kinds: views and time-series collections may be synced by Full Refresh only; capped collections are refused by adops validate, because their oldest documents disappear on their own.

Heavy reads: large Mongo reads follow ADR-0018: a size-bound heavy: approval in Git, batch-by-batch writes into a hidden copy, one heavy read per Server, and a spread slice on Branches. For Mongo, size comes from the collection statistics, and an Incremental run's size from countDocuments on the cursor filter through its index. Load on the live Mongo is controlled through the connection string's readPreference=secondaryPreferred, which the Assistant suggests when it sees a replica set. adops adds no setting of its own.

Privacy: Assistant discovery reads only dev's Mongo, never a Branch's (which uses stage's Source), and returns structure only: field names, types, how often each appears, and when its shape changed. No document values reach the Assistant; masking was rejected because it always misses something, such as a name inside a notes field.

Messages from Checks and Breaking Changes (run logs, alerts, the Assistant) name a document by its _id only when it is an ObjectId; any other _id could be an email or phone number, so they say "document #N in this run" instead. They never show field values.

Packaging and versions: pymongo ships as the optional extra adops[mongo]. MongoDB 8 is the version CI verifies, with no promise for older ones. Fields inside Child tables are pinned by table name (columns: {orders__items.qty: bigint}).

Deletes: without CDC, an Incremental Sync never sees a deleted document (as with Postgres); a Full Refresh is the way to catch deletes. Writing into Mongo (Reverse Sync) stays out of scope.

Follow-up: DuckDB stays the zero-setup, small-data Warehouse; nothing else fills that role. ClickHouse as a third Warehouse for big data is deferred until a named trigger (ADR-0019): ADR-0004 rejected it only because PyAirbyte could not load it without Docker, and since ADR-0012 dlt loads it and dbt-clickhouse exists.

Considered Options: Mongo as the Warehouse (would need non-SQL Transforms and a new Environment model); keeping each document as one JSON column (simpler Sync, but no column shape for Breaking Changes or built-in Checks, and every dbt model would parse JSON); a PyAirbyte Community Source (Airbyte's Mongo connector is Java and needs Docker, rejected in ADR-0004); "NoSQL" in general (DynamoDB, Cassandra, etc. have no shared shape to test against); CDC through change streams (needs a replica set in CI; deferred); sampling documents before the Sync to guess the shape (misses rare changes) or comparing after the write (bad data already loaded); merging Child table rows by key (a removed cart item would stay forever); reading only the newest documents for discovery (misses the shapes of old documents).