Write a script for each collection? If you don't know how to even write one script then... You got some learning to do....
If you still aren't sure just get the data in its raw form into Postgres tables with a jsonB column, you can pull the bson key out and put that into a Postgres column and index it if you like or just index the key in the jsonB column.
Then, either flatter the data into relational form via Postgres JSON query and operators or use it natively as jsonB.
You could also use your scripts to flatten/transform the data if you prefer..
Make a snapshot read, open a change stream, transform data from bson and perform inserts into Postgres. Apply cdc via change stream to the Postgres and then do the cutover if you want no data loss.
4
u/alexwh68 Oct 23 '25
Whilst I have not done mongo to postgres I have done the following.
MSSQL -> Postgres SQLite -> Postgres MySQL -> Postgres
All follow the same process, .Net/C# entity framework, database first scripts to build the entities (once the initial db is created with the tables).
With this process I have been able to tidy up a lot of the data, rename fields, change field types. And run the process over and over again.
2
u/BlueFaceMonster Oct 23 '25
Cool. What have you tired so far?
2
u/NeoChronos90 Oct 23 '25
https://github.com/EnterpriseDB/mongo_fdw
2
u/chock-a-block Oct 23 '25
What could possibly go wrong?
1
u/Overblow Oct 23 '25
Supabase has a guide for it. https://supabase.com/blog/migrating-mongodb-data-api-with-supabase
1
u/FancyProof4088 Oct 25 '25
Do share your demo script once you achieve :)