Schema mapping
Documents don't have a fixed shape; tables do. The schema mapping is the bridge — one entry per field, saying which column it goes to and with what type.
How inference works
When you create a migration, NoSQLSync samples documents from the source and records every field path it sees, the types observed at that path, and how often it appears. Each field becomes a column:
- Names are converted to snake_case —
createdAt→created_at,userID→user_id. Characters that aren't valid in identifiers become underscores. - Nullability follows presence: a field missing from some documents becomes a nullable column.
- Primary key defaults to the document ID — MongoDB's
_idbecomes anidcolumn; for DynamoDB it is the table's partition key.
Mixed types
When a field has different types in different documents, NoSQLSync picks the type that can hold every value:
- Integers mixed with decimals → double.
- Anything mixed with an object or array → JSON.
- Otherwise the widest type wins, in the order string → double → int → boolean → date → ObjectId. A field that is sometimes a string and sometimes a number becomes text.
Type reference
Source types map to target columns as follows:
| Source | PostgreSQL | MySQL / MariaDB | SQL Server | BigQuery | Snowflake | Redshift | ClickHouse |
|---|---|---|---|---|---|---|---|
| ObjectId | VARCHAR(24) | VARCHAR(24) | NVARCHAR(24) | STRING | VARCHAR(24) | VARCHAR(24) | String |
| string | TEXT | TEXT | NVARCHAR(MAX) | STRING | TEXT | VARCHAR(MAX) | String |
| int | INTEGER | INT | INT | INT64 | NUMBER | INTEGER | Int64 |
| double | DOUBLE PRECISION | DOUBLE | FLOAT | FLOAT64 | FLOAT | DOUBLE PRECISION | Float64 |
| boolean | BOOLEAN | TINYINT(1) | BIT | BOOL | BOOLEAN | BOOLEAN | Bool |
| date | TIMESTAMPTZ | DATETIME | DATETIME2 | TIMESTAMP | TIMESTAMP_TZ | TIMESTAMPTZ | DateTime64(3,'UTC') |
| object / array | JSONB | JSON | NVARCHAR(MAX) | JSON | VARIANT | SUPER | String |
| binary | BYTEA | LONGBLOB | VARBINARY(MAX) | BYTES | BINARY | VARBYTE | String |
| null / unknown | TEXT | TEXT | NVARCHAR(MAX) | STRING | TEXT | VARCHAR(MAX) | String |
Every column can be overridden in the Schema mapper — for example, narrowing a TEXT status field to VARCHAR(32).
When the source is a SQL database, copies within the same family (PostgreSQL → PostgreSQL, MySQL → MariaDB) keep the native column types. Cross-engine copies map by category and keep precision, length and time-zone awareness.
Nested objects and arrays
Each nested path can be stored in one of three ways. NoSQLSync suggests one based on your data; you can change it per path.
| Strategy | Result | Suggested when |
|---|---|---|
| Flatten | address.city → column address_city | The object has the same few keys in at least ~90% of documents (up to 8 fields). |
| JSON | One JSONB / JSON / VARIANT column holding the whole value | The shape varies, or the value is rarely queried. |
| Child table | A separate table with one row per array element | An array of sub-documents you'll want to join or aggregate. |
Child tables
Given an orders collection where each document has an items array, a child table looks like this:
CREATE TABLE orders (
id VARCHAR(24) PRIMARY KEY,
customer_id VARCHAR(24),
total DOUBLE PRECISION,
created_at TIMESTAMPTZ
);
CREATE TABLE orders_items (
orders_id VARCHAR(24), -- the parent order
array_index INTEGER, -- position in the array
sku TEXT,
quantity INTEGER,
price DOUBLE PRECISION,
PRIMARY KEY (orders_id, array_index),
FOREIGN KEY (orders_id) REFERENCES orders(id) ON DELETE CASCADE
);Child tables are named <parent>_<path>. During live sync, whenever a parent document changes its child rows are replaced as a set, so element removals and reorders are reflected. They are available for MongoDB sources writing to PostgreSQL, MySQL or MariaDB. On other targets, arrays are stored as JSON.
Relationships and indexes
NoSQLSync looks for fields that reference other collections — ObjectId values and fields named like customerId or customer_id — and shows them as suggested relationships. On PostgreSQL and MySQL-family targets it creates an index on each, up to ten per table. Apart from child tables, foreign-key constraints between tables are not created, so loads never fail on ordering or orphaned references; add them yourself after cutover if you want them enforced.
Editing the mapping over the API
Introspection saves the result as the migration's mapping, keeping any columns you have already edited.
POST /migrations/:id/schema/introspect
{
"nestedDecisions": {
"address": "flatten",
"items": "child-table",
"metadata": "jsonb"
}
}PUT /migrations/:id/schema
{
"mappings": [
{ "sourceField": "_id", "targetColumn": "id", "sqlType": "VARCHAR(24)", "nullable": false, "isPrimaryKey": true },
{ "sourceField": "email", "targetColumn": "email", "sqlType": "TEXT", "nullable": true, "isPrimaryKey": false },
{ "sourceField": "createdAt", "targetColumn": "created_at", "sqlType": "TIMESTAMPTZ", "nullable": true, "isPrimaryKey": false }
]
}Exporting DDL and dbt models
From the Schema mapper you can download the mapping as:
- SQL DDL —
CREATE TABLEstatements for the parent and all child tables, to review or apply yourself. - A dbt project — a zip with sources, staging models and basic tests for every table.
The same inference engine powers the free schema tools, so you can try it on a sample JSON file without an account.