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.
The UK Road Safety Data comprises three CSV files: accidents7904.csv
, casualty7904.csv
, and vehicles7904.csv
. Use this recipe to import the Accidents7904.csv
file into MongoDB.
Run the following command at the command line:
./Applications/mongodb-3.0.4/bin/mongoimport --db pythonbicookbook --collection accidents --type csv --headerline --file '/Data/Stats19-Data1979-2004/Accidents7904.csv' --numInsertionWorkers 5
After running that command, you should see something similar to the following screenshot:
The following command is what you would use for Windows:
C:\Program Files\MongoDB\Server\3.0\bin\mongoimport --db pythonbicookbook --collection accidents --type csv --headerline --file C:\Data\Stats19-Data1979-2004...