driver <- dbDriver("PostgreSQL")
con <- dbConnect(driver, host="localhost", port=5432, dbname="movies", user="postgres")
query <- "select m.mid, m.title, m.director, re.name, ra.stars from movie m inner join rating ra on m.mid = ra.mid inner join reviewer re on
ra.rid = re.rid"
rs <- dbSendQuery(con, query)
movies <- dbFetch(rs, n=-1)
head(movies)
## mid title director name stars
## 1 106 LOGAN James Mangold Sarah Martinez 4
## 2 103 DUNKIRK Christopher Nolan Sarah Martinez 1
## 3 101 GET OUT Jordan Peele Sarah Martinez 5
## 4 105 LADY BIRD Greta Gerwig Sarah Martinez 4
## 5 102 THE BIG SICK Michael Showalter Sarah Martinez 5
## 6 104 WONDER WOMAN Patty Jenkins Sarah Martinez 2
Using home brew
brew install mongodb
mongod # to start mongodb
movies_collection = mongo(collection = "movies", db = "movies_db")
movies_collection$insert(movies)
## List of 5
## $ nInserted : num 48
## $ nMatched : num 0
## $ nRemoved : num 0
## $ nUpserted : num 0
## $ writeErrors: list()
nrow(movies)
## [1] 48
movies_collection$count()
## [1] 48
unlist(movies_collection$iterate()$one())
## mid title director name
## "106" "LOGAN" " James Mangold" "Sarah Martinez"
## stars
## "4"
Advantages
Non-Relational means table-less: NoSQL databases are non-relational, hence, very different from SQL databases. This means they are easier to manage and they provide a higher level of flexibility with newer data models.
Mostly Open Source and Low-Cost: The open source nature of NoSQL databases makes them an appealing solution for smaller organizations with limited budgets. The top NoSQL databases on the market today (MongoDB, MarkLogic, Couchbase, CloudDB, and Amazon’s Dynamo DB) allow for rapid processing of real-time Big Data applications in ways that are affordable.
Easier scalability through Sharding: NoSQL database experts often use elastic scalability as a major selling point of NoSQL. NoSQL databases are designed to function on full throttle even with low-cost hardware.
No need to develop a detailed database model: The non-relational nature of a NoSQL database allows database architects to quickly create a database without needing to develop a detailed (fine-grained) database model. This saves a lot of development time.
Disadvantages
Community not as well defined: While its continuing to grow rapidly, the NoSQL community is relatively new and lacks the maturity of the MySQL user base. Obviously, NoSQL is growing rapidly, but for now MySQL is hard to beat for its vast network of highly experienced end users.
Lack of reporting tools: A major problem with NoSQL databases is the lack of reporting tools for analysis and performance testing. However, with relational dbs, you can find a wide array of reporting tools to help you prove your application’s validity.
Lack of standardization: In order for NoSQL to grow, it needs a standard query language like SQL.