Export from MongoDB to CSV
【Question】
How do you export from Mongodb to CSV? (Python is preferred)
The problem is to export nested complex JSON data to flat CVS with duplicate entries. That’s called denormalisation.
The JSON data:
Putin
-bwm
-porche
For every option I need full data about user, so in Excel the JSON data looks like:
name car
Putin bmw
Putin porche
【Answer】
To export multilevel MongoDB data to structured two-dimensional data involves big data handling and structured data manipulation. It’s difficult to accomplish it in Python. Here I try to deal with it in professional structured data computation language – Structured Process Language (SPL). The code is simple:
A |
|
1 |
=mongo_open(“mongo://localhost:27017/local?user=test&password=test”) |
2 |
=mongo_shell(A1,”testcar.find()”) |
3 |
=A2.news(A2.car;~:car,A2.name:name) |
4 |
=file(“D:\\data.csv”).export@tc(A3;) |
5 |
>mongo_close(A1) |
SPL Official Website 👉 https://www.scudata.com
SPL Feedback and Help 👉 https://www.reddit.com/r/esProc_SPL
SPL Learning Material 👉 https://c.scudata.com
SPL Source Code and Package 👉 https://github.com/SPLWare/esProc
Discord 👉 https://discord.gg/cFTcUNs7
Youtube 👉 https://www.youtube.com/@esProc_SPL