mongoDB – import a CSV file in a database collection

Suppose if you have a CSV file with large number of records and you want to import it into  database collection then need to use

mongoimport 

mongoimport --db users --collection contacts --type csv --headerline --file contacts.csv
--db

will specify database,

--collection

will represent contacts collection

--type

is representing that  CSV file

--headerline

is representing the top line in file is header or column names.

--file

is path to file to import

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.