Importing a Collection

Importing Data

Situation: You need to import an array of objects (i.e., a collection) in Mongo.

Assuming you have the collection already stored in a JSON file, here’s the shell command to import:

$ mongoimport file-name.json -d databaseName -c collectionName --jsonArray --drop

The breakdown is:

-d databaseName
-c collectionName
--jsonArray  # importing an array of objects
--drop       # drop existing collection of same name to use most recent (optional)

For more content on data science, R, and Python find me on Twitter.

Previous
Next