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:

db.myCoinList.renameCollection("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:

[
 {
   "purchDate": "1/17/2018 19:00",
   "symbol": "BTC",
   "name": "Bitcoin",
   "baseCurrency": "BTC",
   "price": 1,
   "amount": 1,
   "total": 1
 },
 {
   "purchDate": "1/17/2018 19:00",
   "symbol": "EXP",
   "name": "Expanse",
   "baseCurrency": "BTC",
   "price": 0.000386362,
   "amount": 11.44779029,
   "total": 0.00442299
 },
 {
   "purchDate": "1/17/2018 18:58",
   "symbol": "DASH",
   "name": "Dash",
   "baseCurrency": "BTC",
   "price": 0.07010228,
   "amount": 0.04999994,
   "total": 0.0035051
 },
 {
   "purchDate": "1/17/2018 18:23",
   "symbol": "LTC",
   "name": "Litecoin",
   "baseCurrency": "BTC",
   "price": 0.01595504,
   "amount": 0.5,
   "total": 0.00797752
 },
 {
   "purchDate": "1/17/2018 18:19",
   "symbol": "ARDR",
   "name": "Ardor",
   "baseCurrency": "BTC",
   "price": 0.00010248,
   "amount": 50,
   "total": 0.005124
 },
 {
   "purchDate": "1/17/2018 18:15",
   "symbol": "STEEM",
   "name": "Steem",
   "baseCurrency": "BTC",
   "price": 0.00032879,
   "amount": 10,
   "total": 0.0032879
 },
 {
   "purchDate": "1/17/2018 18:11",
   "symbol": "XRP",
   "name": "Ripple",
   "baseCurrency": "BTC",
   "price": 0.00010024,
   "amount": 10,
   "total": 0.0010024
 },
 {
   "purchDate": "1/17/2018 18:09",
   "symbol": "DGB",
   "name": "DigiByte",
   "baseCurrency": "BTC",
   "price": 0.00000508,
   "amount": 200,
   "total": 0.001016
 },
 {
   "purchDate": "1/17/2018 18:08",
   "symbol": "DOGE",
   "name": "Dogecoin",
   "baseCurrency": "BTC",
   "price": 6.2e-7,
   "amount": 1500,
   "total": 0.00093
 },
 {
   "purchDate": "1/17/2018 18:05",
   "symbol": "BCY",
   "name": "Bitcrystals",
   "baseCurrency": "BTC",
   "price": 0.00007177,
   "amount": 10,
   "total": 0.0007177
 }
]

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. Required fields are marked *