I am using Mongodb for this assignment

Loading libraries

library(RMySQL)
## Loading required package: DBI
library(mongolite)
## Warning: package 'mongolite' was built under R version 3.4.3
library(jsonlite)
#drv = dbDriver("MySQL")
#con <- dbConnect(drv, user = 'root', password = 'mysql', dbname = 'mysql')

Set up MySql connection

mydb = dbConnect(MySQL(), user='root', password='mysql', dbname='mysql')
#dbListTables(mydb)

Loading Tables

I already made these tables in mysql for assignment3 so using the same tables for movie ratings,user information and movies list tables From str() looking at rows of the table to compare later

movie_table <- dbReadTable(mydb, "movie_list")
str(movie_table)
## 'data.frame':    10 obs. of  4 variables:
##  $ movie_name: chr  "Peter Rabbit" "jumanji:welcome to jungle" "wonder" "padmavat" ...
##  $ movie_id  : int  1 2 3 4 5 6 7 8 9 10
##  $ movie_year: int  2018 2017 2017 2018 2018 2017 2017 2017 2017 2017
##  $ genre     : chr  "Animation" "Action" "Drama" "Historical" ...
movie_ratings <- dbReadTable(mydb, "movie_rating")
str(movie_ratings)
## 'data.frame':    5 obs. of  2 variables:
##  $ rating_id         : int  1 2 3 4 5
##  $ rating_description: chr  "poor" "fair" "good" "very good" ...
user <- dbReadTable(mydb,"user_list")
str(user)
## 'data.frame':    6 obs. of  5 variables:
##  $ user_id        : int  1 2 3 4 6 5
##  $ user_first_name: chr  "Rick" "Tony" "Jag" "Nam" ...
##  $ user_last_name : chr  "singh" "shoker" "singh" "Deep" ...
##  $ user_age       : int  5 33 40 45 50 65
##  $ user_country   : chr  "USA" "CANADA" "CANADA" "USA" ...

Laoding data to Mongodb

used the “mongolite” library to connect to the MongoDB collection and put the relational database into it (using the $insert() function) and using count() to look for number of rows

m <- mongo("test", url = "mongodb://localhost:27017")
mongo_movies <- mongo(collection = "movies", db = "db")
mongo_movies$remove('{}')
mongo_movies$insert(movie_table)
## List of 5
##  $ nInserted  : num 10
##  $ nMatched   : num 0
##  $ nRemoved   : num 0
##  $ nUpserted  : num 0
##  $ writeErrors: list()
mongo_movies$count() 
## [1] 10
mongo_rating <- mongo(collection = "ratings",db = "db")
mongo_rating$remove('{}')
mongo_rating$insert(movie_ratings)
## List of 5
##  $ nInserted  : num 5
##  $ nMatched   : num 0
##  $ nRemoved   : num 0
##  $ nUpserted  : num 0
##  $ writeErrors: list()
mongo_rating$count()
## [1] 5
mongo_user <- mongo(collection = "user", db = "db")
mongo_user$remove('{}')
mongo_user$insert(user)
## List of 5
##  $ nInserted  : num 6
##  $ nMatched   : num 0
##  $ nRemoved   : num 0
##  $ nUpserted  : num 0
##  $ writeErrors: list()
mongo_user$count() 
## [1] 6
Comparision

From the str() [used for Mysql] and count() [used for mongodb] we are comparing the data and the seems to be good without any difference.

Advantages and Disadvantages Between NoSQL and SQL
  1. Data models: A NoSQL database lets us build an application without having to define the schema first unlike relational databases which make define schema before adding any data to the system.

  2. Data structure: Relational databases were built in an era where data was fairly structured and clearly defined by their relationships. NoSQL databases are designed to handle unstructured data (e.g., texts, social media posts, video, email) which makes up much of the data that exists today.

  3. Scaling: It’s much cheaper to scale a NoSQL database than a relational database because you can add capacity by scaling out over cheap, commodity servers. Relational databases, on the other hand, require a single server to host your entire database

I found it easy to work with Mongodb compared to Mysql .Loading of data was much easier and quering was simpler too.