I want to read a CSV file and insert each row as separate document of MongoDB collection, each column from the header of the file, I want to read as key for each document. Please suggest how it can be done,
Asked
Active
Viewed 3,436 times
0
-
Please tell us what you have tried – hyades Nov 22 '16 at 07:34
-
It looks like you want us to write some code for you? We usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (output, tracebacks, etc.). The more detail you provide, the more answers you are likely to receive. Check the FAQ and How to Ask. – Taufiq Rahman Nov 22 '16 at 07:35
1 Answers
1
Mongo has a tool to import the csv files into collection. The tool name is mongoimport. You can find it in mongo website.
You can try that. It will definitely help to meet this requirement. No need to write code.
https://docs.mongodb.com/manual/reference/program/mongoimport/
Example:-
mongoimport --db users --collection contacts --type csv --headerline --file /opt/backups/contacts.csv

notionquest
- 37,595
- 6
- 111
- 105