1. LPU MCA Semester 1
  2. CAP570
  3. Unit 6

CAP570 · Unit 6: Advanced databases

NoSQL databases

15 practice questions · in the ETE syllabus

Key points

  • Four types: key-value, document, column-family, graph
  • Horizontal scaling and flexible schema
  • BASE favours availability and eventual consistency
  • CAP: not all of C, A and P at once

NoSQL ("not only SQL") databases are non-relational systems designed for large scale and flexible data. They usually scale horizontally by adding commodity servers, allow a flexible schema, and often relax ACID in favour of availability.

TypeStoresExamples
Key-valueValues looked up by keyRedis
DocumentJSON-like documentsMongoDB
Column-familyWide rows grouped by column familyCassandra, HBase
GraphNodes and relationshipsNeo4j

In a document store, documents in one collection can have different fields, so a query may test whether a field exists. A graph database answers relationship questions such as friends of friends by following edges. Many NoSQL systems follow BASE (Basically Available, Soft state, Eventual consistency) instead of ACID: a replica can briefly return an old value until the update reaches it.

The CAP theorem says a distributed store cannot guarantee Consistency, Availability and Partition tolerance all at once, so during a network partition it must choose consistency or availability.

Exam trap: NoSQL does not mean there is no SQL-like querying, and eventual consistency is a trade-off, not a defect.

Try two questions

Question 1 · Tier 2, Understand

MongoDB stores JSON-like records. Which type of NoSQL database is it?

  1. Key-value store
  2. Graph database
  3. Column-family store
  4. Document database
Show the answer

D. MongoDB stores JSON-like documents.

Why not A: Redis is a typical key-value store.

Why not B: Neo4j is a typical graph database.

Why not C: Cassandra is a typical column-family store.

Question 2 · Tier 3, Apply

Which property is a typical advantage of NoSQL databases for web-scale applications?

  1. A rigid schema, so every record must have the same columns
  2. A guarantee of ACID transactions across all nodes at all times
  3. A flexible schema, so new fields can be added without altering a table definition
  4. A requirement to normalise all data to third normal form
Show the answer

C. Schema flexibility makes it easy to evolve data models.

Why not A: Rigid schemas are typical of relational databases.

Why not B: Many NoSQL systems relax ACID guarantees.

Why not D: Normalisation is a relational design technique.