1 Introduction

The purpose of this assignment was to load SQL data from a MYSQL server (in this case - MySQL hosted on Azure) to a NoSQL Database (Mongo DB Server in Azure). I choose MongoDB because it is one of the most popular NoSQL databases on the market.

For this project, I used the the following libraries:

  • DBI
  • mongolite

2 SQL Part

In this section, I loaded data from my assignment 3 movies database. I used the following query to join and store into a dataframe:

mysql_movies <- dbGetQuery(con, ‘select u.username, u.firstname, u.lastname, m.title, m.category, m.length, mr.rating, mr.review from users as u join users_movierating as umr on u.userid = umr.userid join movierating as mr on umr.movieratingid = mr.movieratingid join movies as m on mr.movieid = m.movieid;’)

pwd_file <- "/Users/davidapolinar/Dropbox/CUNYProjects/Srping2019/Data607/Week 13/password.txt"

localuserpassword <-read.delim(pwd_file, header = FALSE, stringsAsFactors = FALSE)
con <- dbConnect(RMariaDB::MariaDB(), user='x-admin@cunyspsmysql', password=localuserpassword$V1, dbname='moviereviews' ,host='cunyspsmysql.mysql.database.azure.com')
#con <- dbConnect(RMariaDB::MariaDB(), user='rreadonly@cunyspsmysql', password="", dbname='moviereviews' ,host='cunyspsmysql.mysql.database.azure.com')

dbListTables(con)
## [1] "movierating"       "movies"            "users"            
## [4] "users_movierating"
dbListFields(con, 'movies')
## [1] "movieid"  "title"    "length"   "director" "category"
mysql_movies <- dbGetQuery(con, 'select u.username, u.firstname, u.lastname, m.title, m.category, m.length, mr.rating, mr.review from users as u
join users_movierating as umr on u.userid = umr.userid
                           join movierating as mr on umr.movieratingid = mr.movieratingid
                           join movies as m on mr.movieid = m.movieid;')

head(mysql_movies)
##   username firstname lastname                       title  category length
## 1 RussellS   Russell        S Mission Impossible: Fallout    action    148
## 2 RussellS   Russell        S      Avengers: Infinity War    action    149
## 3 RussellS   Russell        S             The Quiet Place    horror     90
## 4 RussellS   Russell        S                  DeadPool 2    comedy    119
## 5 RussellS   Russell        S               Incredibles 2 animation    118
## 6 RussellS   Russell        S             The Equalizer 2     crime    121
##   rating
## 1      5
## 2      2
## 3      5
## 4      5
## 5      5
## 6      3
##                                                                                                                                                                                                 review
## 1                                                                                          The best thrilling movie ever made! With the best movie character ever portrayed: Tom Cruise as Ethan Hunt!
## 2 At stake, as ever, is the fate of the universe. Why must it always be the universe? What's wrong with the fate of Hackensack? Doesn't anyone care what happens to South Dakota, or Denmark, or Peru?
## 3                                                                                                             This is a movie about the sound of fear, but it gives us a great deal more to listen to.
## 4                                                                                                                                Deadpool 2 is an R-rated, potty-mouthed splatterfest and a funny one.
## 5                                                                                                                          How great to see them back in this funny, exciting, if less audacious film.
## 6                                                                                                                                 Once it's over, you won't necessarily be itching for an Equalizer 3.

4 Conclusion

R makes the loading of dataframes into MongoDB extremely simple with the user of its libaries. As long as the data is in a dataframe format, the loading is simple and intuitive.