Expert Group of programming
Loading...

How to export MongoDB DATA into CSV/json/tsv

Posted by : Heycode Tech | Posted in : MongoDB | Mar 23,2016 | 0 comments

As we know that MONGODB is one of the most popular database.Here we are going to describe about the MONGO EXPORT i.e exporting MONGODB Data into CSV/JSON/TSV file.

I have tested this command on LINUX-UBUNTU System.

I understand that you have already created the DATABASE as well as COLLECTION in MONGODB.

Here we are describing the two methods for exporting the mongodb DATA .
1: Export the complete Database.
2: Export the single collection data.

1: Export the complete Database.

in mongodb 3.0 or above, we should specify the database name to dump. Below is the command which is used to dump.

mongodump

You need to put the value of database name and dump directory.
Suppose your database Name = ‘heycodetech’ and dump directory path = /home/heycodetech/Document/dumpDB
then command is used –

mongodump -d heycodetech -o /home/heycodetech/Document/dumpDB

For importing the dump, Click Here for more in details .

2:Export the single collection data.

For exporting the single collection,we need to follow this syntax.


mongoexport ‐‐db dbname ‐‐collection collectionName ‐‐out filename.json/csv/tsv

Now you need to change the following details .
dbname = Database Name
collectionName= Collection of mongoDB
filename.json/csv/tsv = Please enter the filename with proper extension like data.json or data.csv .

For more details,you can join the official documents Click Here

Note :
1: Filename must be match with filetype otherwise it creates problem.

EXPORT DATA into CSV format
Here is an example for exporting data into the CSV format.It has the following details.
Database Name = heycodetech
Collection Name= secure
File Name = data.csv


Command used :
mongoexport ‐‐db heycodetech ‐‐collection secure ‐‐out data.csv

mongoExport

Now if you need to export the data into the json format then here is the command .


Command used :
mongoexport ‐‐db heycodetech ‐‐collection secure ‐‐out data.json

Please review it and let me know if you have any issues/suggestion.Drop one comment and our expert will respond quickly.

Thanking you .

Tags:

Author information - Heycode Tech

Every world can ask question and my website registered user give the suggestion.

See all posts by Author

Connect to author

About us

Heycodetech is a platform where you can ask any questions related to the programming like PHP,jQuery, MYSQL,HTML , CSS and moreHere is the Expert group of programming.