JavaScript Object Notation (JSON) is becoming the number one format for data exchange on the Web. Modern REST APIs return data in the JSON format, and MongoDB stores the records as binary-encoded JSON documents called BSON. Use the following recipe to import JSON documents into MongoDB.
As we've done in previous import recipes, we'll be using the mongoimport
utility to import the data in the JSON file into MongoDB. By default, mongoimport
expects a JSON file unless told otherwise.
The command for importing a JSON file is almost the same as we used for importing a CSV file:
./Applications/mongodb-3.0.4/bin/mongoimport --db pythonbicookbook --collection accidents --type json --headerline --file '/Data/Stats19-Data1979-2004/Accidents7904.json' --numInsertionWorkers 5