Codementor Events

Mongo Db export using cmd

Published May 17, 2019

MongoDb export

mongoexport command is use for exporting data into json or csv format.

Steps
1.Start Mongo instance
2.Start cmd in administrator mode

Export collection into json
Only mongoexport command not work.! For that you have to specify
database name as well as collection name. You also need to specify
output parameter (file name).

mongoexport --db StudentDb --collection stud --out stud.json

Export collection into CSV
For csv export , you need to specify the type. Most important is this csv
required column name. Without column name it gives the error.
mongoexport --db StudentDb --collection stud --type=csv --fields Name,Age --out stud.csv

You can also give the file which contains the fields and then you can export
into csv.

Create fields.txt file and add fields name to be required.

mongoexport --db StudentDb --collection stud --type=csv --fieldFile fields.txt --out stud.csv

Please checkout for this demo on my youtube channel. MongoDb Export

Discover and read more posts from Khatri Karan
get started
post commentsBe the first to share your opinion
Show more replies