Free tool

MongoDB schema → SQL DDL

Paste documents from any collection. Get the inferred columns, the type mapping, and a CREATE TABLE statement for your target database — using the same inference engine that runs a real migration.

Your documents
A JSON array, one object, or one object per line — whatever mongoexport gave you.
CREATE TABLE
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
);
Inferred fields — 9 columns from 2 documents
FieldColumnBSON typeSQL typeNullable
_idPKidobjectIdVARCHAR(24)no
address.cityaddress_citystringTEXTyes (0% empty)
address.streetaddress_streetstringTEXTyes (0% empty)
ageageint, doubleDOUBLE PRECISIONyes (0% empty)
emailemailstringTEXTyes (0% empty)
lastSeenlast_seennullTEXTyes (100% empty)
signedUpAtsigned_up_atdateTIMESTAMPTZyes (0% empty)
tagstagsarrayJSONByes (50% empty)
teamIdteam_idobjectIdVARCHAR(24)yes (0% empty)

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.

Proposed relational model

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.

address
embedded object · in 100% of documents

A consistently-shaped embedded object. Flattening it into prefixed columns makes the fields directly queryable and indexable, with no join.

→ address_city TEXT
→ address_street TEXT
orders
object array · in 100% of documents · 1.5 elements avg

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.

→ table users_orders (price, qty, sku)
→ price DOUBLE PRECISION
→ qty INTEGER
→ sku TEXT
tagsKeep as JSON
scalar array · in 50% of documents · 2.0 elements avg

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.

Foreign key candidates
team_id→ teamshighHolds an ObjectId in every sampled document, which in MongoDB almost always points at another collection.

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 →