PostHeaderIcon Importing a CSV file into MongoDB

Importing data from a CSV file into MongoDB is one of the fastest methods of import available. It is also one of the easiest. With almost every database system exporting to CSV, the following recipe is sure to come in handy.

we just do the following:

mongoimport --db smallbusiness --collection company
 --type csv --headerline --file '/Users/Jerry/Downloads
/data/company.csv' --numInsertionWorkers 5



Each part of the command has a specific function:

mongoimport: The MongoDB utility that we will use to import the data.
-- db smallbusiness: Specifies the name of the database to use.
-- collection company: Tells the tool the name of the collection to use; if the collection doesn't exist, it will be created automatically.
--type csv: Specifies that we're importing a CSV file.
--headerline: Tells the import tool that our CSV file has a headerline containing the column headers.
--file '/Users/Jerry/Downloads/data/company.csv': The full path to the file which contains the data that we're importing.
--numInsertionWorkers 5: By default, MongoDB uses a single worker to import the data. To speed this up, we specify the use of 5 workers.

Here’s the result of the process:

Here’s the result of the import:

Have a good day, friends.

1839 views

Leave a Reply

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

*


*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>


Copyright © 2010 - C++ Technology. All Rights Reserved.

Powered by Jerry | Free Space Provided by connove.com