library(odbc)
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(dbplyr)
##
## Attaching package: 'dbplyr'
## The following objects are masked from 'package:dplyr':
##
## ident, sql
db <- DBI::dbConnect(odbc::odbc(), "SQL")
movie <- as.data.frame(db %>% tbl("movie"))
movie
## movie_id movie_name movie_genre
## 1 1 The Nun Terror
## 2 2 Peppermint Adventure
## 3 3 God Bless the Broken Road Action
## 4 4 The Apparition Action
## 5 5 The Meg Action
## 6 6 Mile 22 Action
rating <- as.data.frame(db %>% tbl("rating"))
rating
## rating_id user_id movie_id movie_rating
## 1 1 1 1 4
## 2 2 2 2 4
## 3 3 3 3 4
## 4 4 4 4 4
## 5 5 5 5 5
## 6 6 6 6 3
merge(movie,rating, by = c('movie_id'), all.x=TRUE)
## movie_id movie_name movie_genre rating_id user_id
## 1 1 The Nun Terror 1 1
## 2 2 Peppermint Adventure 2 2
## 3 3 God Bless the Broken Road Action 3 3
## 4 4 The Apparition Action 4 4
## 5 5 The Meg Action 5 5
## 6 6 Mile 22 Action 6 6
## movie_rating
## 1 4
## 2 4
## 3 4
## 4 4
## 5 5
## 6 3
Loading Data Into MongoDB
library(mongolite)
mdb_movie = mongo(collection = "movie", db = "movie")
library(mongolite)
mdb_rating = mongo(collection = "rating", db = "rating")
mdb_movie$insert(movie)
## List of 5
## $ nInserted : num 6
## $ nMatched : num 0
## $ nRemoved : num 0
## $ nUpserted : num 0
## $ writeErrors: list()
mdb_rating$insert(rating)
## List of 5
## $ nInserted : num 6
## $ nMatched : num 0
## $ nRemoved : num 0
## $ nUpserted : num 0
## $ writeErrors: list()
alldata_movie <- mdb_movie$find('{}')
head(alldata_movie)
## movie_id movie_name movie_genre
## 1 1 The Nun Terror
## 2 2 Peppermint Adventure
## 3 3 God Bless the Broken Road Action
## 4 4 The Apparition Action
## 5 5 The Meg Action
## 6 6 Mile 22 Action
alldata_rating <- mdb_rating$find('{}')
head(alldata_rating)
## rating_id user_id movie_id movie_rating
## 1 1 1 1 4
## 2 2 2 2 4
## 3 3 3 3 4
## 4 4 4 4 4
## 5 5 5 5 5
## 6 6 6 6 3
merge(head(alldata_movie),head(alldata_rating), by = c('movie_id'), all=TRUE)
## movie_id movie_name movie_genre rating_id user_id
## 1 1 The Nun Terror 1 1
## 2 2 Peppermint Adventure 2 2
## 3 3 God Bless the Broken Road Action 3 3
## 4 4 The Apparition Action 4 4
## 5 5 The Meg Action 5 5
## 6 6 Mile 22 Action 6 6
## movie_rating
## 1 4
## 2 4
## 3 4
## 4 4
## 5 5
## 6 3