Migrate MongoDB to MySQL
Beta — live-tested pathThe converter maps 15 MongoDB column types to MySQL. 5 of them change kind on the way (ObjectId becomes varchar(24), Array becomes json, Object / subdocument becomes json, and more); the table below lists every one. Documents become rows: the schema is inferred by sampling the collection, and nested data lands in JSON columns. DBShifts creates the inferred tables, copies the documents in parallel batches and checks the result with row counts.
Free tier · no credit card
MongoDB vs MySQL
MongoDB
the leading document database.
MySQL
the world's most deployed open-source relational database.
MongoDB to MySQL data type mapping
Pulled directly from DBShifts's own conversion rules — not a general reference table, this is what actually runs.
| MongoDB | MySQL |
|---|---|
| ObjectId | varchar(24) |
| String (up to 255 chars) | varchar(255) |
| String (longer) | LONGTEXT |
| Int32 | int |
| Int64 | bigint |
| Double | double |
| Decimal128 | decimal(38,9) |
| Boolean | tinyint(1) |
| Date | datetime |
| Timestamp | timestamp |
| Binary | LONGBLOB |
| Array | json |
| Object / subdocument | json |
| UUID | varchar(36) |
| Null | LONGTEXT |
Example: MongoDB to MySQL conversion
MongoDB
// one document from the "orders" collection
{
"_id": ObjectId("6512c3a1f4b2e9d0a7c1b234"),
"customer_id": NumberLong(4821),
"total": NumberDecimal("129.99"),
"is_gift": false,
"notes": "leave at reception",
"tags": ["priority", "fragile"],
"placed_at": ISODate("2026-03-14T09:20:00Z")
}MySQL
CREATE TABLE IF NOT EXISTS `orders` (
`_id` varchar(24),
`customer_id` bigint NOT NULL,
`total` decimal(38,9) NOT NULL,
`is_gift` tinyint(1),
`notes` varchar(255),
`tags` json,
`placed_at` datetime NOT NULL,
PRIMARY KEY (`_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;The schema comes from a sample
MongoDB declares no schema, so the column list is inferred by sampling documents. Every field seen in the sample becomes a column; a nullable value does not poison the inference, so a field that is sometimes null and otherwise an integer stays an integer column.
Sampling has a known blind spot: a field present in one document in a million may not be sampled at all. Check the analysis output for the rare fields you know exist, an admin flag or a legacy key, before the load rather than after.
_id becomes a varchar(24) primary key
ObjectId becomes its 24-character hex form and the primary key. The hex string sorts in the same order as the ObjectId, and an ObjectId begins with its creation time, so ORDER BY _id still returns documents in roughly insertion order.
Foreign references between collections, a customer_id holding an ObjectId, arrive as the same hex strings, so joins work on text equality. MySQL will not enforce them as foreign keys until you declare them, which is worth doing only once the data has been checked for dangling references.
Nested documents land in JSON columns
Subdocuments and arrays become MySQL json columns. Nothing is lost, and nothing is split into child tables either. JSON_EXTRACT and the ->> operator read single values, and JSON_TABLE turns an array into rows for a join.
If one nested field is queried constantly, a generated column over it with an index gives the speed of a real column without changing the data.
MongoDB → MySQL conversion notes
Engine-specific rules baked into the conversion and transfer pipeline — verified by live certification of this exact pair.
- Schema is inferred by sampling documents — null values don't poison type inference (a nullable int stays an int column).
- Decimal128 maps to exact DECIMAL on SQL targets, never a float round-trip.
- Nested documents and arrays land as JSON/JSONB columns with data preserved byte-for-byte.
- _id becomes the primary key; ObjectId converts to its 24-character hex form.
- AUTO_INCREMENT counters are reseeded to MAX(id)+1 after bulk load, so the first production insert doesn't collide.
- Oversized VARCHAR definitions from other engines are rewritten to TEXT/LONGTEXT to respect MySQL's row-size limits.
- Foreign keys are applied after data load with FOREIGN_KEY_CHECKS deferred for speed and ordering safety.
Frequently asked questions
Is MongoDB to MySQL migration production-ready in DBShifts?
MongoDB to MySQL is in beta. It runs on real servers in the certification suite, which checks it by row counts; the content checks that certify the SQL pairs do not yet compare documents with rows. Every migration still ends with a fidelity report to audit before cutover.
What happens to MongoDB types that MySQL doesn't have?
Each gets the nearest MySQL type the converter treats as safe: ObjectId becomes varchar(24), Array becomes json, Object / subdocument becomes json, UUID becomes varchar(36), Null becomes LONGTEXT. Every such decision is in the migration plan before anything runs, and any mapping can be overridden per column.
Can I keep MongoDB and MySQL in sync after the initial migration?
Yes, until you cut over. DBShifts follows a change stream from a resume token taken before the first document is copied. Change streams need a replica set or a sharded cluster; a standalone server cannot stream.
Which MongoDB data types need a second look when moving to MySQL?
The table above carries a note on 5 of them: ObjectId (varchar(24)), Decimal128 (decimal(38,9)), Array (json), Object / subdocument (json) and more. Analysis flags the same columns on your own schema before any data moves.
Go deeper
Migrating MongoDB to SQL (and Back) Without Losing Your Schema
How relational structure is inferred from collections, and what happens to Decimal128 and nested documents.
How We Live-Certified All 49 Migration Paths
The certification harness behind this page's claims.
Rehearse the Migration: Dry Runs, Quarantine, and Rollback
Rehearse, isolate failures, and keep the exit open.
Reference
Compared with other tools
Ready to move MongoDB to MySQL?
Set up in under two minutes. Validation and rollback included.
Start Free Migration