An Interest In:
Web News this Week
- April 27, 2024
- April 26, 2024
- April 25, 2024
- April 24, 2024
- April 23, 2024
- April 22, 2024
- April 21, 2024
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
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To