Load Packages

library(RMySQL)
## Loading required package: DBI
library(mongolite)

MySQL

Here we pull the data from mySQL.

con<-(dbConnect(MySQL(), user="root", password="1234", dbname="flights", host="35.225.71.0"))

dbListFields(con, 'Ratings')
## [1] "Person"                        "TheLionKing"                  
## [3] "Avengers_Endgame"              "Aladdin"                      
## [5] "Toy_Story_5"                   "Spiderman_Homecoming"         
## [7] "Godzilla_King_of_the_Monsters"
Mysql<-"Select * from Ratings"
movie_ratings<-dbGetQuery(con, Mysql)
movie_ratings
##   Person TheLionKing Avengers_Endgame Aladdin Toy_Story_5
## 1   Tony           5                5       4           4
## 2   Dana           5                5       4           5
## 3  Jimmy           5                5       5           5
## 4 Daniel           3                4       4           4
## 5 Johnny           4                5       4           5
## 6    Lin           4                5       4           5
##   Spiderman_Homecoming Godzilla_King_of_the_Monsters
## 1                    4                             4
## 2                    4                             3
## 3                    5                             5
## 4                    3                             3
## 5                    2                             5
## 6                    4                             2
#disconnect from the database
dbDisconnect(con)
## [1] TRUE

MongoDB

After we pull the ratings from mySQL, we connect to a MongoDB. Make sure theres a connection. Run a count function to make sure the database is empty

con <- mongo(collection = 'movie_ratings', db = 'Ratings')

con$count("{}")
## [1] 6

Insert the ratings in Mongo

con$insert(movie_ratings)
## List of 5
##  $ nInserted  : num 6
##  $ nMatched   : num 0
##  $ nRemoved   : num 0
##  $ nUpserted  : num 0
##  $ writeErrors: list()

Print out the database from MongoDB.

alldata <- con$find('{}')
print(alldata)
##    Person TheLionKing Avengers_Endgame Aladdin Toy_Story_5
## 1    Tony           5                5       4           4
## 2    Dana           5                5       4           5
## 3   Jimmy           5                5       5           5
## 4  Daniel           3                4       4           4
## 5  Johnny           4                5       4           5
## 6     Lin           4                5       4           5
## 7    Tony           5                5       4           4
## 8    Dana           5                5       4           5
## 9   Jimmy           5                5       5           5
## 10 Daniel           3                4       4           4
## 11 Johnny           4                5       4           5
## 12    Lin           4                5       4           5
##    Spiderman_Homecoming Godzilla_King_of_the_Monsters
## 1                     4                             4
## 2                     4                             3
## 3                     5                             5
## 4                     3                             3
## 5                     2                             5
## 6                     4                             2
## 7                     4                             4
## 8                     4                             3
## 9                     5                             5
## 10                    3                             3
## 11                    2                             5
## 12                    4                             2

Advantages of No-SQL

  1. No-SQL have easy and flexible schema which allows for easier migration of data.

  2. No-SQL databases like MongoDB also scale and perform better than SQL databases.

Disadvantages of No-SQL

  1. Hard to deal with databases with many links(with primary keys).

  2. Databases that placed more emphasis on connection between different variables would not be that great with a MongoDB document database.