Migrate MongoDB to SQL Server
Beta — live-tested pathThe converter maps 15 MongoDB column types to SQL Server. 5 of them change kind on the way (ObjectId becomes NVARCHAR(24), Array becomes NVARCHAR(MAX), Object / subdocument becomes NVARCHAR(MAX), 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 SQL Server
MongoDB
the leading document database.
SQL Server
Microsoft's enterprise relational database.
MongoDB to SQL Server data type mapping
Pulled directly from DBShifts's own conversion rules — not a general reference table, this is what actually runs.
| MongoDB | SQL Server |
|---|---|
| ObjectId | NVARCHAR(24) |
| String (up to 255 chars) | NVARCHAR(255) |
| String (longer) | NVARCHAR(MAX) |
| Int32 | INT |
| Int64 | BIGINT |
| Double | FLOAT(53) |
| Decimal128 | DECIMAL(38,9) |
| Boolean | BIT |
| Date | DATETIME2 |
| Timestamp | DATETIMEOFFSET |
| Binary | VARBINARY(MAX) |
| Array | NVARCHAR(MAX) |
| Object / subdocument | NVARCHAR(MAX) |
| UUID | NVARCHAR(36) |
| Null | NVARCHAR(MAX) |
Example: MongoDB to SQL Server 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")
}SQL Server
IF OBJECT_ID(N'orders', 'U') IS NULL
CREATE TABLE [orders] (
[_id] NVARCHAR(24),
[customer_id] BIGINT NOT NULL,
[total] DECIMAL(38,9) NOT NULL,
[is_gift] BIT,
[notes] NVARCHAR(255),
[tags] NVARCHAR(MAX),
[placed_at] DATETIME2 NOT NULL,
CONSTRAINT [PK_orders] PRIMARY KEY ([_id])
);Nested data becomes NVARCHAR(MAX) JSON text
Subdocuments and arrays become NVARCHAR(MAX) holding the JSON text, which every supported SQL Server version can store and query. The functions added in SQL Server 2016 work on it: JSON_VALUE reads one value, OPENJSON turns an array into rows, and ISJSON can back a CHECK constraint if the column should only ever hold valid documents.
NVARCHAR(MAX) cannot be indexed directly. Add a computed column over JSON_VALUE() and index that for any nested field that is searched often.
_id as an NVARCHAR(24) clustered key
_id becomes NVARCHAR(24) and the primary key, which in SQL Server is clustered by default. ObjectIds start with a timestamp, so new rows append near the end of the index instead of splitting pages in the middle, which is the behaviour you want from a clustered key.
NVARCHAR spends two bytes per character on what is pure hex, 48 bytes a key. VARCHAR(24) halves that in the clustered index and in every nonclustered index that carries the key, which is worth changing on large collections.
Double and Decimal128
A BSON Double becomes FLOAT(53), the same 8-byte float. Decimal128 becomes DECIMAL(38,9), exact but with a fixed scale of nine: more fractional digits than that are rounded on the way in.
Check the fields that carry long fractions before the load. A DECIMAL with a larger scale is a per-field override, and it costs nothing if made before any data moves.
MongoDB → SQL Server 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.
- IDENTITY_INSERT is managed per table so explicit IDs from the source load correctly, then counters are reseeded with DBCC CHECKIDENT.
- Binary columns always carry an explicit length — bare VARBINARY (which means 1 byte) never reaches the target.
- TRUNCATE falls back to DELETE on FK-referenced tables automatically.
Frequently asked questions
Is MongoDB to SQL Server migration production-ready in DBShifts?
MongoDB to SQL Server 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 SQL Server doesn't have?
Each gets the nearest SQL Server type the converter treats as safe: ObjectId becomes NVARCHAR(24), Array becomes NVARCHAR(MAX), Object / subdocument becomes NVARCHAR(MAX), UUID becomes NVARCHAR(36), Null becomes NVARCHAR(MAX). Every such decision is in the migration plan before anything runs, and any mapping can be overridden per column.
Can I keep MongoDB and SQL Server 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 SQL Server?
The table above carries a note on 5 of them: ObjectId (NVARCHAR(24)), Decimal128 (DECIMAL(38,9)), Array (NVARCHAR(MAX)), Object / subdocument (NVARCHAR(MAX)) 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.
What Is Database Migration? A Plain-English Guide
What a migration involves, and why it is harder than copying files.
Reference
Compared with other tools
Ready to move MongoDB to SQL Server?
Set up in under two minutes. Validation and rollback included.
Start Free Migration