mongoexport gave you.CREATE TABLE "users" (
"id" VARCHAR(24) NOT NULL PRIMARY KEY,
"address_city" TEXT,
"address_street" TEXT,
"age" DOUBLE PRECISION,
"email" TEXT,
"last_seen" TEXT,
"signed_up_at" TIMESTAMPTZ,
"tags" JSONB,
"team_id" VARCHAR(24)
);
CREATE TABLE "users_orders" (
"users_id" VARCHAR(24) NOT NULL,
"array_index" INTEGER NOT NULL,
"price" DOUBLE PRECISION,
"qty" INTEGER,
"sku" TEXT,
PRIMARY KEY ("users_id", "array_index"),
FOREIGN KEY ("users_id") REFERENCES "users"("id") ON DELETE CASCADE
);This is the schema a migration writes: one column per field, with consistently-shaped embedded objects flattened into prefixed columns you can query and index directly. A consistently-shaped array of subdocuments can become its own table with a foreign key back to this one — toggle it below.
A faithful copy is not a relational schema. Here is the structure hiding inside these documents — which nested parts deserve their own tables, which flatten into columns, and which really are just JSON. The embedded objects are yours to change.
A consistently-shaped embedded object. Flattening it into prefixed columns makes the fields directly queryable and indexable, with no join.
Repeating subdocuments with a consistent shape. This is a one-to-many relationship: a child table with a foreign key back to the parent is the relational form.
An array of scalars has no internal structure to normalise. Keep it as JSON, or split it into a child table later if you need to query the elements individually.
Both toggles above are applied — flatten an embedded object into columns, or promote an array of subdocuments into its own table, and the DDL updates with it (PostgreSQL, MySQL and MariaDB targets only for child tables). Running this against your real collection samples 500 documents instead of the handful you pasted, which is what makes the shape and frequency numbers meaningful. Connect a database →
Run it against your real database
NoSQLSync samples your collections, infers the schema, and migrates the data with live CDC. Free plan, no credit card.
Start free →