DEV Community


Posted on

How to import csv data in mongoDB

Question: How to add CSV data in mongoDB Atlas or local mongoDB?
1) MongoDB command line utility mongoimport is used to import csv/json data in mongoDB. It is bundled in MongoDB Database Tools package which can be downloaded by vising Tools section on mongoDB official website. Here is the link to download this

2) After installing to your machine to the install folder and run the following command
mongoimport --uri "mongodb+srv://" --collection=collection_name --mode=insert --type=csv --headerline --file=d:\data\userlist.csv

Replace username, password, database_name, collection_name and --file with your own values. Also replace with your own cluster address. Full database connect string including cluster address can be found on Database page by pressing Connect button. --mode=insert will append data into your collection. --headerline will tell mongo that first line contains field names. For full mongoimport options please visit official documentation at

For local mongoDB instance instead of --uri, --hostname can be used. Syntax will be like --host=<:port>

Top comments (0)