# Convert MongoDB to PostgreSQL

> Convert MongoDB documents to PostgreSQL tables with a reviewed mapping and checks before cutover. Review relationships, preserve source IDs, and verify the result before switching.

Canonical: https://layerbase.com/convert/mongodb-to-postgresql
Generated from Layerbase source: 2026-11-08

Review a proposed relational schema before moving documents into tables. The source _id stays with each root row, and unmapped fields can be preserved as JSONB.

## How it works

1. **Read the schema.** A schema profile records field paths, types, and counts. Deterministic rules suggest tables and columns from that profile. No document values are sent to a model.
2. **Review the mapping.** Review one root table per collection, child tables for arrays, column names, types, and JSONB overflow. Edit suggestions and validate relationships before explicitly approving foreign keys.
3. **Copy into a new target.** Pause source writes before copying. A deterministic copier reads the source and writes the approved mapping into an empty PostgreSQL target. Retries use a new target.
4. **Verify before switching.** Stop writes on the source, press Re-verify, and switch your application connection only after the checks pass. There is no continuous change replication.

## What is verified before cutover

- Row counts: root rows match source document counts, and child rows match the source array lengths.
- ID checksum: an order-independent checksum compares the preserved source IDs with the target IDs.
- Field coverage: every observed path is mapped or preserved in JSONB overflow. The report shows overflow counts.
- Sampled round trip: sampled target rows and their children are rebuilt into documents and compared with the source.

## What does not carry over unchanged

- The Mongo wire protocol and query language do not carry over. Update your application to use PostgreSQL.
- MongoDB indexes, validators, TTL behavior, and change streams are not transferred. Review the PostgreSQL indexes in your mapping.
- Credentials and transaction semantics change. Test authentication and application behavior before switching.
- Splitting one collection into multiple root tables is outside the first version.

## Conversion questions

### Can I keep my MongoDB driver?

No. PostgreSQL uses a different protocol and query language. Update your application before cutover.

### Are document values sent to a model?

No. Mapping suggestions use deterministic rules over field names, types, and counts. The copier and relationship validator read source records without sending document values to a model.

### What happens to _id and fields outside the mapping?

The source _id values stay intact as text. The default PostgreSQL column is id when no source field collides; otherwise it remains _id. You can rename the target column during review, and approved references follow the mapping. JSONB overflow preserves fields outside the approved columns.

### Which accounts can convert?

Conversion requires feature availability and an eligible paid plan with confirmed payment. Free plans, complimentary grants, and active Pro trials cannot start a conversion. You can end a Pro trial early from your plan page after reviewing and confirming the charge. Access unlocks after payment is confirmed.

### Does verification compare every value byte for byte?

No. Counts, ID checksums, and approved relationship checks cover the full dataset. Ordinary document reconstruction samples up to 200 records per collection. The report separates mismatches from explained substitutions, including invalid UTF-8 fields whose original bytes remain recoverable and are checked in full.

### Is the source changed?

The source is read-only throughout. You control the write freeze and application cutover; Layerbase does not switch your application for you.

## Start conversion

[Start conversion](https://layerbase.com/cloud/create/from-source?provider=mongodb-atlas&target=postgresql)

[All conversion paths](https://layerbase.com/convert)

[Conversion guide](https://layerbase.com/docs/converting-engines)
