Migrate a whole database
Every table becomes a collection in one run.
- Schema and table names become database and collection names
- Start here when the MongoDB side is still empty
Migrate PostgreSQL data to MongoDB seamlessly with Withdata DBToMongo — no complex coding required. Support for all MongoDB deployment types (standalone, replica sets, sharded clusters, MongoDB Atlas).
Works on Windows, macOS, Linux (Debian, Ubuntu, Fedora, RHEL, openSUSE).
See How to Migrate PostgreSQL data to MongoDB Free Trial Download - DBToMongoBefore diving into the migration process, let’s understand the unique strengths of these two databases — and why businesses often need to bridge them:
PostgreSQL (Postgres) is an enterprise-grade open-source relational database management system (RDBMS) renowned for its robustness, extensibility, and compliance with SQL standards. It uses tables, rows, and columns with rigid schemas, adhering to ACID (Atomicity, Consistency, Isolation, Durability) principles. Key use cases include:
PostgreSQL’s strengths lie in its open-source flexibility, advanced SQL capabilities, and enterprise-grade reliability. However, businesses often migrate to MongoDB for greater scalability with unstructured data, horizontal scaling, and modern cloud-native application development.
MongoDB is a leading document-oriented NoSQL database designed for flexibility and scalability. It stores data in BSON (Binary JSON) documents, allowing dynamic schemas that adapt to evolving application requirements. Key use cases include:
MongoDB’s strengths include handling unstructured/semi-structured data, seamless horizontal scaling, and integration with modern development stacks. Migrating PostgreSQL data to MongoDB enables businesses to leverage these strengths while preserving valuable data from relational systems.
Common scenarios for PostgreSQL-to-MongoDB migration include:
A PostgreSQL table is a rectangle; a MongoDB collection is a bag of documents. The work is deciding which table becomes which collection, and what each column looks like inside the document.
Every table becomes a collection in one run.
One table in, one collection out.
Filter on the PostgreSQL side, then export.
SELECT with joins and WHERE defines the documentsOne table per month or per branch becomes one collection.
_idMany tables, one pass.
Field by field, decided once.
jsonb → nested object, timestamptz → Datenumeric → Decimal128; bytea → BinDataRe-run the session instead of re-importing.
Run it on a timer.
.bat or .shlocalhost, rds-postgres01.xxxx.us-east-1.rds.amazonaws.com), port (5432), database name (e.g., postgres)postgres@localhost:5432:adventureworksmongodb://localhost:27017/local or mongodb+srv://atlas_user:@cluster0.mongodb.net/ Choose the perfect migration method for your needs:
| Migration Type | Use Case | Example |
|---|---|---|
| Query to Collection | Export filtered data via custom PostgreSQL query | Extract sales data: SELECT order_id, customer_id, order_date, total_amount FROM sales.orders WHERE order_date > '2023-01-01' |
| 1 to 1 | Migrate one PostgreSQL table to one MongoDB collection | PostgreSQL hr.employees → MongoDB employees |
| N to 1 | Combine multiple PostgreSQL tables into one collection | sales.orders_2024 + sales.order_2025 → MongoDB orders |
| N to N | Batch migrate tables to separate collections | products→products, categories→categories, suppliers→suppliers |
TIMESTAMPTZ to MongoDB timestamps (preserve time zones)JSONB/ARRAY/hstore to MongoDB BSON types| PostgreSQL | BSON (MongoDB) |
|---|---|
integer / bigint | Int32 / Int64 |
numeric / decimal | Decimal128 |
double precision | Double |
boolean | Boolean |
text / varchar | String |
jsonb / json | nested document |
array (_int4, text[]) | BSON array |
timestamptz / timestamp | Date |
bytea | BinData |
uuid | String (or BinData) |
numeric only keeps its precision as Decimal128, and int becomes a 32-bit BSON int that overflows quietly if the column grows._id automatically: map the key column to _id if you want a stable identity, otherwise MongoDB generates a new ObjectId per document.jsonb become documents and arrays, so a later table-to-collection run cannot shove them back into a plain column.job_title stays job_title — plan for it if your application expects camelCase..bat (Windows) or .sh (Linux/macOS) scripts from saved sessions.C:\Users\{user_name}\AppData\Local\DBToMongo\{date}.log (Windows) or ~/.config/DBToMongo/{date}.log (Linux/macOS).Source Query: SELECT employee_id, first_name, last_name, job_title, department_id, hire_date FROM hr.employees WHERE department_id = 10
Target Collection: employees
Migration Result: 24 records migrated in 0.8 seconds.
| employee_id | first_name | last_name | job_title | department_id | hire_date |
|---|---|---|---|---|---|
| 1 | Ken | Sanchez | Chief Executive Officer | 10 | 2009-01-14 09:00:00+00 |
| 2 | Terri | Duffy | Vice President of Engineering | 10 | 2008-01-26 10:00:00+00 |
| 3 | Roberto | Tamburello | Engineering Manager | 10 | 2007-11-11 11:00:00+00 |
| 4 | Rob | Walters | Senior Engineering Manager | 10 | 2007-01-05 08:00:00+00 |
| 5 | Gail | Erickson | Engineering Manager | 10 | 2008-01-01 09:00:00+00 |
| 6 | Jossef | Goldberg | Senior Design Engineer | 10 | 2009-02-15 10:00:00+00 |
No, and it is worth being precise about: there is no transform stage. It reads rows (a table, a query result or a whole database) and writes them, on demand or on a schedule. What arrives is a copy of the source shape, not a pipeline with joins, lookups and aggregations. If the transformation matters, do it in the query you hand the tool — that is the only place it runs.
host=rds-postgres01.xxxx.us-east-1.rds.amazonaws.com port=5432 dbname=adventureworks user=postgres password=xxxx sslmode=require) and MongoDB Atlas URI, then migrate directly between cloud services.hr, sales, analytics) and can preserve schema names in MongoDB collection names (e.g., hr_employees).Ready to Migrate PostgreSQL to MongoDB Effortlessly?
Download DBToMongo Free Trial