MongoDB to PostgreSQL
Turn MongoDB collections into PostgreSQL tables you can query with SQL. Weld lands each collection as a table, with top-level fields as columns or the whole document as JSON, and keeps it current with incremental syncs.
Checked against Weld and vendor docs on
Your own tables, picked when you set up the sync.
- Extract
- Load
- Keep in sync
- mongodb.Synced
- mongodb.Syncing
- mongodb.Synced
- mongodb.Synced
Trusted by data and AI teams
Three ways to get MongoDB data into PostgreSQL
Going from documents to rows means deciding what happens to nested fields. Each method below answers that differently, and that choice shapes every query you write afterwards.
mongoexport and a load script
- Best for
- A one-off export of a few collections
- Effort
- Medium: export, flatten, create tables, load
- Freshness
- Whenever you rerun it
- Good to know
- Exports Extended JSON or CSV; CSV needs an explicit field list. MongoDB says it is not a backup tool. Flattening nested documents and typing columns is up to your script.
AWS Database Migration Service
- Best for
- Teams on AWS who want full load plus CDC
- Effort
- Medium: replica set, endpoints, mode choice, tasks
- Freshness
- Full load, then ongoing replication
- Good to know
- Document mode puts each document in a _doc column; table mode flattens nested fields into dot-named columns from a scan of 1,000 documents by default. CDC needs a replica set for the oplog.
Weld
- Best for
- Querying MongoDB data next to other sources in PostgreSQL
- Effort
- Low: connection string, pick collections, choose pack mode
- Freshness
- Incremental syncs on your schedule
- Good to know
- Unpacked mode makes top-level fields columns and keeps nested objects as JSON; packed mode lands id plus the whole document. Merge syncs use _id by default.
How to sync MongoDB to PostgreSQL with Weld.
In the app, with the API or an agent.
What lands in PostgreSQL
From MongoDB to PostgreSQL.
MongoDB has no fixed schema, so there is no list of tables to publish. Each collection you select becomes one PostgreSQL table, in the shape your pack mode decides.
- Unpacked collection tables
One column per top-level field, including _id, with data types inferred. A nested object such as nested: { name: 3 } lands as JSON in a single nested column.
- Packed collection tables
Two columns: id and json, the full document. Useful when documents in a collection vary a lot and you prefer to parse fields in SQL.
- _weld_synced
The time Weld synced each row. Use it to check freshness and to build incremental models on top.
Does each collection have one row per document, and how fresh is it?
In PostgreSQL SQL.
Runs in PostgreSQL against a collection synced in unpacked mode, assuming you named the destination schema mongodb. Replace orders with one of your collections. _id comes from MongoDB and _weld_synced from Weld.
1select2 count(*) as row_count,3 count(distinct "_id") as documents,4 max(_weld_synced) as last_synced5from mongodb."orders"Ask your agent.
It queries PostgreSQL for you.
Connect Claude, Cursor, ChatGPT or your own agent to Weld over MCP. It reads the MongoDB context, finds the tables it needs and runs the query in PostgreSQL.
Which MongoDB tables do we have in PostgreSQL, and which is the largest?
Looking up what Weld has synced from MongoDB.
Things to know.
Before you sync MongoDB.
- Nested documents stay JSON below the first level
- Unpacked mode unpacks one layer of nested fields. Anything deeper stays as JSON in its top-level column, so plan to extract nested values in SQL models rather than expecting one column per path.
- The default _id cursor only sees new documents
- Syncs run in incremental merge mode on _id by default, and _id reflects creation time, so updates to existing documents are missed. Set the cursor to a field that records modification time, and index it in MongoDB.
- Switching pack mode re-syncs the table
- Changing a collection between packed and unpacked mode triggers a full re-sync of that table, and its columns change shape. Pick the mode before you build models on it.
- Deletes are not covered by scheduled syncs
- Weld's MongoDB docs do not describe delete handling for incremental syncs. MongoDB CDC, which streams document deletes, is listed as coming soon, so check deleted documents yourself if they matter to your reports.
Common questions.
About MongoDB to PostgreSQL.
Start syncing MongoDB to PostgreSQL.
Set up your MongoDB data pipeline in minutes. No credit card required. Free for 14 days.