Skip to content

MongoDB data type reference

MongoDB to PostgreSQL, MySQL, SQL Server, Oracle and Db2: type mapping

How a MongoDB collection becomes a table: what each BSON type becomes in each target, and what happens when documents disagree.

Updated · from our Database Migration Platform’s type rules

Where these mappings come from

The defaults our platform proposes

Each target type below is the default our Database Migration Platform proposes for a MongoDB column, and every project can override any of them. The notes are what we check when planning a migration: where a value can round, lose information or behave differently on the new engine. “Same type” means the type name is kept; check binary lengths and time precision on the target.

MongoDB to each target: testing status
MongoDB → PostgreSQLNightly end-to-end test: inserts, updates and deletes
MongoDB → MySQLSupported, not yet tested
MongoDB → SQL ServerSupported, not yet tested
MongoDB → OracleSupported, not yet tested
MongoDB → Db2Supported, not yet tested

BSON types

  • ObjectId

    PostgreSQL
    TEXT
    MySQL
    TEXT
    SQL Server
    NVARCHAR(MAX)
    Oracle
    CLOB
    Db2
    CLOB

    Lands as its 24-character hex string, as unbounded text. On targets other than PostgreSQL, override _id to VARCHAR(24) to use it as a key. The timestamp inside an ObjectId is no longer queryable as a date.

  • string, symbol

    PostgreSQL
    TEXT
    MySQL
    TEXT
    SQL Server
    NVARCHAR(MAX)
    Oracle
    CLOB
    Db2
    CLOB

    Strings have no declared length, so they land as unbounded text: TEXT on MySQL holds 64 KB.

  • int (int32)

    PostgreSQL
    INTEGER
    MySQL
    INT
    SQL Server
    INT
    Oracle
    NUMBER(10)
    Db2
    INTEGER

    If later documents hold a larger number in the same field, those values no longer fit; see type drift below.

  • long (int64)

    PostgreSQL
    BIGINT
    MySQL
    BIGINT
    SQL Server
    BIGINT
    Oracle
    NUMBER(19)
    Db2
    BIGINT

    Fits every target.

  • double

    PostgreSQL
    DOUBLE PRECISION
    MySQL
    DOUBLE
    SQL Server
    FLOAT
    Oracle
    BINARY_DOUBLE
    Db2
    DOUBLE

    8-byte floating point.

  • decimal128

    PostgreSQL
    NUMERIC
    MySQL
    DECIMAL
    SQL Server
    DECIMAL
    Oracle
    NUMBER
    Db2
    DECIMAL

    An exact decimal of 34 digits. It lands as unbounded NUMERIC on PostgreSQL, not a double, so money values keep every digit. MySQL, SQL Server and Db2 need an explicit precision, or their small defaults round the values.

  • bool

    PostgreSQL
    BOOLEAN
    MySQL
    TINYINT(1)
    SQL Server
    BIT
    Oracle
    NUMBER(1)
    Db2
    SMALLINT

    A true boolean on PostgreSQL; BIT on SQL Server and 0 or 1 elsewhere.

  • date, timestamp

    PostgreSQL
    TIMESTAMP(6)
    MySQL
    DATETIME(6)
    SQL Server
    DATETIME2
    Oracle
    TIMESTAMP
    Db2
    TIMESTAMP

    BSON dates are UTC milliseconds; they land without a zone, so treat them as UTC. A BSON Timestamp is seconds plus a counter, not a date, and the counter is lost.

  • binData

    PostgreSQL
    BYTEA
    MySQL
    LONGBLOB
    SQL Server
    VARBINARY(MAX)
    Oracle
    BLOB
    Db2
    BLOB

    UUIDs stored as binData arrive as bytes, not as a UUID type.

  • embedded document, array

    PostgreSQL
    JSONB
    MySQL
    JSON
    SQL Server
    NVARCHAR(MAX)
    Oracle
    CLOB
    Db2
    CLOB

    Each nested document or array lands as one JSON column with the source’s key names. Nested dates, ObjectIds and decimals become JSON strings or numbers, and JSONB does not keep key order. The change-capture pipeline cannot carry arrays that mix types (["a", 1, true]); those documents are set aside.

Planning a MongoDB migration? We can map your schema and run the move with change data capture.

Database migration services

Beyond types

What a type table does not show

The schema can convert cleanly and the application still break. These are the usual reasons with MongoDB.

01

One collection, one table

Top-level scalar fields become columns. Each nested document or array becomes one JSON column (JSONB on PostgreSQL). Inserts, updates and deletes all follow through change streams.

02

Type drift

Documents in one collection need not agree on a field’s type. In our platform a column takes the type of the first value it receives; later values that fit are converted, and a document whose value cannot be stored (qty: "seven" in a number column) is set aside with the reason while the rest keep flowing.

03

Replica set required

Change streams need a replica set or a sharded cluster. A single server can run as a one-member replica set.

Notes per target

Landing in each database

Into PostgreSQL

  • Unquoted names fold to lower case, and names are cut at 63 bytes. Pick lower-case names that fit before creating the schema.
  • Identity columns land as GENERATED BY DEFAULT AS IDENTITY. Our platform moves each sequence past the current maximum after the load and again at cutover; if you load by hand, use setval, or the first insert collides.
  • Text cannot hold the NUL character (0x00). Find and clean such values before the load.
  • Comparisons are case-sensitive by default. Use citext or a nondeterministic ICU collation where the source compared case-insensitively.

Into MySQL

  • Create the database with utf8mb4. The older utf8 (utf8mb3) cannot store emoji and some other characters.
  • All columns except TEXT and BLOB share a 65,535-byte row limit, and utf8mb4 counts up to 4 bytes a character. CHAR(n) allows at most 255.
  • Text with no declared length lands as TEXT, which holds 64 KB: override to MEDIUMTEXT or LONGTEXT for larger values. TEXT and BLOB columns need a prefix length to be indexed.
  • TIME has no fractional seconds unless declared TIME(6), so fractions are lost. DATETIME(6) holds microseconds but no time zone.
  • A boolean arrives as TINYINT(1): 0 or 1, though the column also accepts other small integers.

Into SQL Server

  • Text lands as NVARCHAR/NCHAR, so Unicode is safe. NVARCHAR(n) allows n up to 4,000: longer declared lengths need NVARCHAR(MAX), which cannot be an index key.
  • Most SQL Server databases compare case-insensitively, unlike PostgreSQL, Oracle and Db2.
  • Identity columns are not re-seeded automatically: run DBCC CHECKIDENT after the load.
  • DATETIME2 keeps up to 100 ns. DATETIMEOFFSET keeps an offset, but values from a UTC source (such as PostgreSQL timestamptz) arrive as +00:00.
  • JSON lands as NVARCHAR(MAX). SQL Server 2025 has a native json type if you want one.
  • There is no boolean type: BIT holds 0, 1 or NULL.

Into Oracle

  • Oracle treats an empty string as NULL. Values that were '' in the source become NULL, and NOT NULL text columns can reject them.
  • Integers land as NUMBER(5), NUMBER(10) and NUMBER(19); booleans as NUMBER(1) (Oracle 23ai has BOOLEAN, but it is not the default); UUIDs as VARCHAR2(36) text.
  • Identity columns are not re-seeded automatically: use ALTER TABLE … MODIFY … START WITH LIMIT VALUE after the load.
  • VARCHAR2 holds 4,000 bytes unless MAX_STRING_SIZE is EXTENDED (32,767); a longer declared length needs a CLOB override. Text with no length lands as CLOB, which cannot be compared with = or used in a plain index.
  • TIME values land as TIMESTAMP, with a date part added.

Into Db2

  • Booleans land as SMALLINT (0 or 1) and UUIDs as VARCHAR(36) text.
  • Timestamps land as plain TIMESTAMP, which keeps 6 fractional digits and no time zone: values with a zone are stored without it, so convert them to UTC first. TIME has no fractional seconds.
  • Identity columns are not re-seeded automatically: use ALTER TABLE … ALTER COLUMN … RESTART WITH after the load.
  • A VARCHAR holds up to 32,672 bytes, CHAR up to 255 and DECIMAL up to 31 digits; wider columns need an override. Text with no length and JSON land as CLOB.
  • The JDBC driver (jcc) ships separately under IBM’s licence.

FAQ

Common questions

How are nested MongoDB documents stored in PostgreSQL?
Each nested document or array lands in one JSONB column with the original key names; top-level fields become ordinary columns. BSON-only types inside, such as dates and ObjectIds, become JSON strings.
What does a MongoDB ObjectId become in PostgreSQL?
Its 24-character hex string, as text, which can be the primary key on PostgreSQL. On MySQL, SQL Server, Oracle and Db2, override it to VARCHAR(24) first.
What happens to MongoDB decimal128 values in PostgreSQL?
They land as an unbounded NUMERIC, not a double, so every one of the 34 digits is kept.