https://grokonez.com/node-js/node-js-extract-mongodb-data-to-csv-file-using-json2csv

Node.js Extract MongoDB Data to CSV File – using Json2Csv

In the tutorial, Grokonez shows how to extract data from MongoDB to CSV File with Node.js using Json2Csv lib.

Technologies

  • Node.js
  • MySQL
  • json2csv

Goal

– We create a Node.js project as below structure: nodejs-export-mongodb-data-to-csv-file---project-structure

– MongoDB Data:

nodejs-export-mongodb-data-to-csv-file---mongodb-records

{"_id":1,"name":"Jack Smith","address":"Massachusetts","age":23}
{"_id":2,"name":"Adam Johnson","address":"New York","age":27}
{"_id":3,"name":"Katherin Carter","address":"Washington DC","age":26}
{"_id":4,"name":"Jack London","address":"Nevada","age":33}
{"_id":5,"name":"Jason Bourne","address":"California","age":36}

– CSV File:


"_id","address","age","name"
1,"Jack Smith",23,"Massachusetts"
2,"Adam Johnson",27,"New York"
3,"Katherin Carter",26,"Washington DC"
4,"Jack London",33,"Nevada"
5,"Jason Bourne",36,"California"

Practice

Install MongoDB & Json2CSV

Init package.json file by cmd: npm init -> Then install mongodb & json2csv libs:

More at:
https://grokonez.com/node-js/node-js-extract-mongodb-data-to-csv-file-using-json2csv

Node.js Extract MongoDB Data to CSV File – using Json2Csv

#nodejs #csv #mongodb #json2csv

Node.js Extract MongoDB Data to CSV File – using Json2Csv » grokonez
1.40 GEEK