Migrate MongoDB to MariaDB
Beta — live-tested pathThe converter maps 15 MongoDB column types to MariaDB. 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 MariaDB
MongoDB
the leading document database.
MariaDB
the community-driven MySQL fork.
MongoDB to MariaDB data type mapping
Pulled directly from DBShifts's own conversion rules — not a general reference table, this is what actually runs.
| MongoDB | MariaDB |
|---|---|
| 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 MariaDB 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")
}MariaDB
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;Inferring a schema from documents that have none
MongoDB collections have no declared schema, so the target columns have to be inferred by sampling documents. That works well when documents are consistent and badly when they are not: a field present in 2% of documents may not appear in the sample at all, and a field holding a string in some documents and a number in others has no single correct column type.
The conservative resolution is to widen. A field seen as both integer and string becomes text, which keeps every value at the cost of type precision. It is worth reviewing the inferred schema before the load rather than after, because a widened column is easy to narrow while the table is empty and expensive to change later.
Nested documents and arrays have no column equivalent
A nested object becomes a JSON column rather than being split into separate columns, and an array becomes a JSON column rather than a child table. Both are defensible defaults, and both mean the data is no longer queryable the way a relational schema would allow: you cannot index an array element as a column or join to it.
Where an array genuinely represents a one-to-many relationship, converting it to a child table is the better long-term shape and requires a modelling decision that no automatic conversion should make silently. Doing the faithful JSON copy first and normalising afterwards keeps both options open.
MariaDB stores JSON as LONGTEXT with validation rather than as a distinct binary type, so JSON functions work but the storage and indexing characteristics differ from a native JSON type.
_id and the primary key
Every document has an _id, and by default it is a 12-byte ObjectId rendered as 24 hexadecimal characters. That becomes a VARCHAR(24) primary key, which works and is larger and less efficient than an integer key for both storage and index size.
If the collection has a natural key already, using it as the primary key and keeping _id as an ordinary indexed column usually produces a better relational schema. ObjectIds also encode their creation time in the leading bytes, so a created_at column can be derived from them where none was stored explicitly.
MongoDB → MariaDB 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.
- Literal 'NULL' defaults reported by MariaDB's information schema are cleaned instead of becoming DEFAULT 'NULL' strings.
- AUTO_INCREMENT reseed after bulk load, same as MySQL.
Frequently asked questions
Is MongoDB to MariaDB migration production-ready in DBShifts?
MongoDB to MariaDB 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 MariaDB doesn't have?
Each gets the nearest MariaDB 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 MariaDB 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 MariaDB?
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.
Masking PII in Flight: Production Data Without Production Risk
Mask during the migration, not after, so real PII never sits in a lower environment.
Reference
Compared with other tools
Errors you may hit
Ready to move MongoDB to MariaDB?
Set up in under two minutes. Validation and rollback included.
Start Free Migration