Manually Importing Data into MongoDB

I am working on a finishing up a project from my bootcamp that I didn’t get fully deployed.  It is an app to teach people about cryptocurrencies and allow them to track cryptos they are interested in.  I am working with a MongoDB backend for storing the cryptos in a person’s list.  Here I’m renaming an existing collection and re-importing some test data into the db to make sure my backend server is serving up data properly.

From inside the cryptoCoin db, I rename collection myCoinList to old-myCoinList:

Next, I used Excel to edit a csv file I want to upload:

I converted it to json using the Convert CSV to JSON site, which gave me a nicely formatted json file:

Then, I used the “mongoimport” function to import the file into MongoDB.  Note that you have to do this from a terminal window, not the Mongo command shell, as “mongoimport” is a separate executable.

The first time I did the import, I forgot to add the “–jsonArray” flag at the end, and got an error.

Finally, I use the mongo shell to make sure that the documents were uploaded.  My collection name is myCoinList, so the command to see the documents in the collection is “db.myCoinList.find({})”.

Using Robo 3T, you can view a Mongo Collection in table mode, which is handy for checking the contents of your data.  You just need to click the “View results in table mode” button in the upper-right corner of the screen.

Leave a Reply

Your email address will not be published.