CE419 Session 26: NoSQL Databases Web Programming
The Relational Model • Relational database management systems require defined and clearly set schemas. • Use SQL to query for data. • Despite their strict nature of forming and handling data, relational databases can become extremely flexible and offer a lot, granted with a little bit of effort.
NoSQL • A NoSQL database provides a mechanism for storage and retrieval of data that is modeled in means other than the tabular relations used in relational databases. • NoSQL database systems do not come with a model as used (or needed) with structured relational solutions. • NoSQL databases do not have a common way to query the data and each solution provides its own query system.
SQL vs. NoSQL • Structure and type of data being kept • Querying • Scaling • Reliability • Support • Complex data keeping and querying needs
NoSQL (cont'd) • Types • Key-Value stores • Graph • Column-oriented • Document • Multi-model
Key-Value Stores • A key-value store, or key-value database, is a computer program designed for storing, retrieving, and managing associative arrays (dictionaries). • Redis: SHOWTIME. • Example usages?
Graph Databases • A graph database is a database that uses graph structures for semantic queries with nodes, edges and properties to represent and store data. • Examples: • Neo4j • FlockDB
Column-oriented Databases S120LondonSmith;S210Paris Jones;S330ParisBlake;S420 LondonClark;S530AthensAda ms SNO STATUS CITY SNAME --- ------ ---- ----- S1 20 London Smith S2 10 Paris Jones S3 30 Paris Blake S4 20 London Clark S5 30 Athens Adams S1S2S3S4S5;2010302030;Lon donParisParisLondonAthens ;SmithJonesBlakeClarkAdam s
Column-oriented Databases (cont'd)
Document Databases • Sometimes data is not easy to describe with relational databases. • Example: a product search engine. { { name: "Peugeot 206", name: "Seagate HDD", price: 36000000, price: 210000, hp: 105, capacity: "500GB", top_speed: 180, rpm: 7200, gearbox: "manual", ports: ["SATA", "USB"], color: "White" color: "Red" } }
Document Databases (cont'd) • Documents may be addressed in the database via a unique key that represents that document. • Auto-increment integer? • UUID, ObjectId
UUID • Universally Unique Identifier • A UUID is simply a 128-bit value. The meaning of each bit is defined by any of several variants. • Human readable display de305d54-75b4-431b-adb2-eb6b9e546014 • The intent of UUIDs is to enable distributed systems to uniquely identify information without significant central coordination.
UUID Variants • Version 1 (MAC Address & date-time) • Single point in time & space • Version 4 (Random) • udid library in Python.
MongoDB • MongoDB is the most popular NoSQL, document based, database system. • MongoDB can still hold various databases of different names within one installation package. • But inside databases are collections , not tables. • A collection may be considered a table except there are no aligned columns.
What does it mean? • Consider a collection of users . • Now each of these entries or rows inside a collection is called a document . • They are basically JSON data blocks.
Querying MongoDB • mongo command opens MongoDB shell. • It's a JavaScript shell!
Querying MongoDB (cont'd) • db.collection.find() • db.collection.insert() • db.collection.update() • etc… • Let's see something in action!
CAP Theorem • CAP theorem states that there are three basic requirements which exist in a special relation when designing applications for a distributed architecture: • Consistency, Availability, Partition Tolerance
Recommend
More recommend