tl  tr
  Home | Tutorials | Articles | Videos | Products | Tools | Search
Interviews | Open Source | Tag Cloud | Follow Us | Bookmark | Contact   
 No SQL > Mongo DB > How to export database collection to CSV or JSON file

How to export database collection to CSV or JSON file 

MongoDB is a scalable, high-performance, open source NoSQL database. It offers Ad hoc queries, Indexing, Replication, Load balancing, File storage (GridFS), Aggregation, MapReduce and Server-side JavaScript execution. A single mongod process runs on one machine, and can host many databases. Each database can have many Collections (Can say "tables" in RDBMS language). The following example shows how to export a Collection using mongoexport utility.

mongoexport -d mytestdb -c students -o students.json
mongoexport -d mytestdb -c students -f  name,age -o students2.json
mongoexport -d mytestdb -c students -f  name,age --csv -o students.csv

Where,

	-d [ --db ] arg             The database to use
	-c [ --collection ] arg     The Collection to export
	-f [ --fields ] arg         Comma separated list of fields to export
	-o [ --out ] arg            Output file to export Content; if not specified, stdout is used
	--csv                       Exports the contents of Collection as CSV instead of JSON.
export2.gif




 
  


  
bl  br