Data Acquisition & Mgmt - Assigment 12

Graph Databases

Objective

To take information from a relational database and migrate it to a NoSQL database of our own choice.

Load libraries

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

Connect to MySQL Database

connection <- dbConnect(MySQL(),
              user="",
              password="",
              dbname="test",
              host="localhost"
)

dbListTables(connection)
## [1] "DS_GenSkills"  "DS_JobList"    "DS_SoftSkills" "Reviewers"    
## [5] "TopMovies"

Query table and create data frame

qry_movie <- "SELECT ID, Title, Genre, Runtime, Director FROM TopMovies"

query <- dbGetQuery(connection, qry_movie)

knitr::kable(query)
ID Title Genre Runtime Director
1 Crazy Rich Asians Comedy 120 Jon M. Chu
2 The Meg Adventure 114 Jon Turteltaub
3 Mission Impossible: Fallout Adventure 147 Christopher McQuarrie
4 Operation Finale Drama 130 Chris Weitz
5 Searching Mystery 101 Aneesh Chaganty
6 Christopher Robin Kids 120 Marc Forster

Load Data into MongoDB

First the connection

mdb = mongo(collection = "data", db = "assign12")

Then drop existing data and load the new ones

mdb$drop()
mdb$count()
## [1] 0
mdb$insert(query)
## List of 5
##  $ nInserted  : num 6
##  $ nMatched   : num 0
##  $ nRemoved   : num 0
##  $ nUpserted  : num 0
##  $ writeErrors: list()

Show Data in MongoDB

mngdata <- mdb$find('{}')

knitr::kable(mngdata)
ID Title Genre Runtime Director
1 Crazy Rich Asians Comedy 120 Jon M. Chu
2 The Meg Adventure 114 Jon Turteltaub
3 Mission Impossible: Fallout Adventure 147 Christopher McQuarrie
4 Operation Finale Drama 130 Chris Weitz
5 Searching Mystery 101 Aneesh Chaganty
6 Christopher Robin Kids 120 Marc Forster

SQL vs NoSQL

Disconnect

## [1] TRUE

Eleanor R Secoquian