As we know that
MONGODB is one of the most popular database.Here we are going to describe about the
MONGO IMPORT i.e importing a CSV/JSON/TSV file into the MONGODB.
I have tested this command on
I understand that you have already created the DATABASE as well as COLLECTION in MONGODB.
Here we are describing the two methods for importing the DATA .
1: Import the complete Database.
2: Import the single collection data.
1: Import the complete Database
in mongodb 3.0 or above, we should specify the database name to restore. Below is the command which is used to restore .
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 –
For exporting the dump, Click Here for more in details .
2: Import the single collection data
For importing the single collection,we need to follow this syntax.
mongoimport ‐‐host=127.0.0.1 -d dbname -c collectionName ‐‐type csv/json/tsv ‐‐file filename.csv ‐‐headerline
Now you need to change the following details .
dbname = Database Name
collectionName= Collection of mongoDB
csv = Define the fileType like csv,tsv or json
filename.csv = Please Enter the correct path of the file .
1: Filename must be match with filetype otherwise it creates problem.
2: Please don’t forgot “–headerline” in the last.
Let’s take an example.
Here is the following details like DBNAME=heycodetech and collection Name=secure and fileName=data.csv
Command used :
mongoimport ‐‐host=127.0.0.1 -d heycodetech -c secure ‐‐type csv ‐‐file data.csv ‐‐headerline
Import the json file into MongoDB
We have taken all the information as same except the file name i.e data.json. So here is the correct syntax.
Command used :
mongoimport ‐‐host=127.0.0.1 -d heycodetech -c secure ‐‐type json ‐‐file data.json ‐‐headerline
Please review it and let me know if you have any issues/suggestion.Drop one comment and our expert will respond quickly.
Thanking you .