Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
April 10, 2022 01:10 am GMT

How to import csv data in mongoDB

Question: How to add CSV data in mongoDB Atlas or local mongoDB?
Answer:
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 https://www.mongodb.com/try/download/database-tools

2) After installing to your machine to the install folder and run the following command
mongoimport --uri "mongodb+srv://username:[email protected]/database_name?retryWrites=true&w=majority" --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 cluster0.xxxxx.mongodb.net 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 https://www.mongodb.com/docs/database-tools/mongoimport/#csv-import

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


Original Link: https://dev.to/prog585/import-csv-in-mongodb-37oo

Share this article:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To