Migrate PostgreSQL to MongoDB — Tables into Collections

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 - DBToMongo

About PostgreSQL & MongoDB: Why This Migration Matters

Before diving into the migration process, let’s understand the unique strengths of these two databases — and why businesses often need to bridge them:

What is PostgreSQL?

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.

What is MongoDB?

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.

Why Migrate PostgreSQL to MongoDB?

Common scenarios for PostgreSQL-to-MongoDB migration include:

What you can do with DBToMongo

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.

Whole database

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
View screenshot
One table

Table to collection

One table in, one collection out.

  • Each row becomes one document
  • The collection is created on the first insert, so there is no schema to write
View screenshot
One table

Query to collection

Filter on the PostgreSQL side, then export.

  • A SELECT with joins and WHERE defines the documents
  • Only the returned rows are written
View screenshot
Many tables

Merge tables into one collection

One table per month or per branch becomes one collection.

  • Columns are matched once, by name
  • Rows are appended in the order you pick, each with its own _id
View screenshot
Many tables

Batch tables to collections

Many tables, one pass.

  • Map each table to its own collection
  • Replace or append is chosen per table
View screenshot
Both sides

Map PostgreSQL types to BSON

Field by field, decided once.

  • jsonb → nested object, timestamptz → Date
  • numeric → Decimal128; bytea → BinData
View screenshot
Both sides

Keep MongoDB current

Re-run the session instead of re-importing.

  • Full sync replaces the collection contents
  • Incremental sync upserts on the key you name (a primary key or a unique column)
View screenshot
Automation

Schedule the job

Run it on a timer.

  • Save the session as .bat or .sh
  • Task Scheduler on Windows, Crontab on Linux, launchd on macOS
View screenshot

Why Choose Our PostgreSQL to MongoDB Tool?

4 Simple Steps to Migrate PostgreSQL to MongoDB

1. Connect to PostgreSQL & MongoDB

2. Select Migration Type & Data Source

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

3. Configure Migration Settings

4. Start Migration & Monitor Progress

PostgreSQL — MongoDB Type Mapping

PostgreSQLBSON (MongoDB)
integer / bigintInt32 / Int64
numeric / decimalDecimal128
double precisionDouble
booleanBoolean
text / varcharString
jsonb / jsonnested document
array (_int4, text[])BSON array
timestamptz / timestampDate
byteaBinData
uuidString (or BinData)

Common Pitfalls When Moving PostgreSQL into MongoDB

  • PostgreSQL has real types; MongoDB does not — numeric only keeps its precision as Decimal128, and int becomes a 32-bit BSON int that overflows quietly if the column grows.
  • Primary keys are not carried as _id automatically: map the key column to _id if you want a stable identity, otherwise MongoDB generates a new ObjectId per document.
  • Arrays and jsonb become documents and arrays, so a later table-to-collection run cannot shove them back into a plain column.
  • Foreign keys, constraints and triggers stay in PostgreSQL: MongoDB receives documents, not relations.
  • Column names are case-sensitive in MongoDB, so job_title stays job_title — plan for it if your application expects camelCase.

Key Migration Features

Flexible Data Handling

Automation & Scheduling

Error Resilience & Compliance

Common Use Cases

Migration Example: PostgreSQL Query to MongoDB Collection

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

Is this an ETL tool?

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.

Frequently Asked Questions

Q: How long does PostgreSQL to MongoDB migration take?
A: Migration speed depends on dataset size, hardware, and network. The tool migrates millions of rows in minutes — 100,000 records take ~30 seconds, 1M records take ~2-3 minutes.
Q: Is the migration process secure?
A: Yes! All data is processed locally on your machine. No PostgreSQL or MongoDB credentials or data are transmitted to external servers. Supports PostgreSQL SSL/TLS encryption and MongoDB TLS/SSL.
Q: Can I migrate data from Amazon RDS PostgreSQL to MongoDB Atlas?
A: Absolutely! Enter your RDS PostgreSQL connection string (e.g., 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.
Q: Can I automate migrations via command line?
A: Yes! Save your migration session in the GUI, then run it via CLI on Windows, Linux, or macOS.
Q: What PostgreSQL and MongoDB versions are supported?
A: Supports PostgreSQL 9.x/10/11/12/13/14/15/16, Amazon RDS for PostgreSQL, Azure PostgreSQL, Google Cloud SQL for PostgreSQL; and MongoDB 3.x/4.x/5.x/6.x (all deployment types: standalone, replica sets, sharded clusters, Atlas).
Q: Does the tool support PostgreSQL schemas (not just public schema)?
A: Yes! The tool supports migration from all PostgreSQL schemas (e.g., 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