Bird
Raised Fist0
DBMS Theoryknowledge~10 mins

NoSQL database types (document, key-value, column, graph) in DBMS Theory - Step-by-Step Execution

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Concept Flow - NoSQL database types (document, key-value, column, graph)
Start: Choose NoSQL type
Use case decides best fit
You pick a NoSQL type based on data structure: documents, key-value pairs, columns, or graphs.
Execution Sample
DBMS Theory
INSERT INTO DocumentDB {"name": "Alice", "age": 30}
PUT KeyValueDB "user123" "Alice"
INSERT INTO ColumnDB (user_id, name) VALUES (123, "Alice")
CREATE NODE GraphDB (id:1, name:"Alice")
CREATE EDGE GraphDB (from:1, to:2, relation:"friend")
Shows how data is stored differently in each NoSQL type.
Analysis Table
StepDatabase TypeOperationData StoredInternal StructureResult
1DocumentInsert{"name": "Alice", "age": 30}JSON-like documentDocument stored with fields name and age
2Key-ValuePutKey: "user123", Value: "Alice"Simple key-value pairKey-value pair stored
3ColumnInsertuser_id=123, name="Alice"Columns grouped in familiesRow inserted with columns
4GraphCreate NodeNode id=1, name="Alice"Node with propertiesNode created
5GraphCreate EdgeEdge from node 1 to 2, relation="friend"Edge connecting nodesEdge created linking nodes
6----Execution ends after all inserts
💡 All data inserted into respective NoSQL database types
State Tracker
VariableStartAfter Step 1After Step 2After Step 3After Step 4After Step 5Final
DocumentDBempty{"name": "Alice", "age": 30}{"name": "Alice", "age": 30}{"name": "Alice", "age": 30}{"name": "Alice", "age": 30}{"name": "Alice", "age": 30}{"name": "Alice", "age": 30}
KeyValueDBemptyempty{"user123": "Alice"}{"user123": "Alice"}{"user123": "Alice"}{"user123": "Alice"}{"user123": "Alice"}
ColumnDBemptyemptyemptyRow with user_id=123, name="Alice"Row with user_id=123, name="Alice"Row with user_id=123, name="Alice"Row with user_id=123, name="Alice"
GraphDB NodesemptyemptyemptyNode 1: {name: "Alice"}Node 1: {name: "Alice"}Node 1: {name: "Alice"}Node 1: {name: "Alice"}
GraphDB EdgesemptyemptyemptyemptyemptyEdge from 1 to 2: {relation: "friend"}Edge from 1 to 2: {relation: "friend"}
Key Insights - 3 Insights
Why does the Document database store data as JSON-like documents instead of simple key-value pairs?
Because Document databases store complex, nested data with multiple fields in one document, unlike Key-Value databases which store only simple pairs. See execution_table rows 1 and 2.
How is data organized differently in Column databases compared to Document databases?
Column databases group data by columns in families for fast queries on specific columns, while Document databases store whole documents. See execution_table rows 1 and 3.
Why do Graph databases have nodes and edges instead of just storing data like other NoSQL types?
Graph databases model relationships explicitly with edges connecting nodes, which helps with connected data queries. See execution_table rows 4 and 5.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution_table at step 2. What kind of data is stored in the Key-Value database?
AA simple key and its associated value
BA JSON document with multiple fields
CColumns grouped in families
DNodes and edges representing relationships
💡 Hint
Check the 'Data Stored' column at step 2 in execution_table
At which step does the Graph database create a connection between two nodes?
AStep 3
BStep 5
CStep 4
DStep 1
💡 Hint
Look for 'Create Edge' operation in execution_table
If you want to store user profiles with many fields and nested data, which NoSQL type from the table is best?
AKey-Value database
BColumn database
CDocument database
DGraph database
💡 Hint
See execution_table row 1 for storing complex data
Concept Snapshot
NoSQL databases store data differently:
- Document: JSON-like documents with fields
- Key-Value: simple key and value pairs
- Column: data in columns grouped by families
- Graph: nodes connected by edges
Choose type based on data shape and query needs.
Full Transcript
NoSQL databases come in four main types: document, key-value, column, and graph. Document databases store data as JSON-like documents with multiple fields, good for complex data. Key-value databases store simple pairs of keys and values, ideal for fast lookups. Column databases organize data by columns grouped in families, useful for queries on specific columns. Graph databases store nodes and edges to represent connected data and relationships. Each type suits different use cases depending on data structure and query patterns.

Practice

(1/5)
1. Which NoSQL database type is best suited for storing data as JSON-like documents with flexible schemas?
easy
A. Graph database
B. Document database
C. Column database
D. Key-value database

Solution

  1. Step 1: Understand document database structure

    Document databases store data as documents, often JSON-like, allowing flexible and nested data.
  2. Step 2: Compare with other NoSQL types

    Key-value stores use simple key-value pairs, column stores organize data by columns, and graph databases focus on relationships.
  3. Final Answer:

    Document database -> Option B
  4. Quick Check:

    Flexible JSON-like storage = Document database [OK]
Hint: JSON-like flexible data means document DB [OK]
Common Mistakes:
  • Confusing key-value with document stores
  • Thinking column stores handle JSON
  • Assuming graph DB stores documents
2. Which of the following is the correct way to describe a key-value store?
easy
A. Stores data as nested JSON documents
B. Stores data as interconnected nodes and edges
C. Stores data in tables with rows and columns
D. Stores data as simple pairs of keys and values

Solution

  1. Step 1: Define key-value store

    Key-value stores save data as pairs: a unique key and its associated value.
  2. Step 2: Eliminate other options

    Nodes and edges describe graph DB, tables describe relational or column DB, nested JSON describes document DB.
  3. Final Answer:

    Stores data as simple pairs of keys and values -> Option D
  4. Quick Check:

    Key-value = key and value pairs [OK]
Hint: Key-value means simple pairs, not complex structures [OK]
Common Mistakes:
  • Mixing graph DB with key-value store
  • Confusing column DB with key-value
  • Thinking document DB is key-value
3. Given a graph database storing people and their friendships, which query result would you expect from a query asking for all friends of 'Alice'?
medium
A. A set of nodes connected to 'Alice' by edges labeled 'friend'
B. A table with columns for friend names and ages
C. A list of key-value pairs with friend names
D. A JSON document containing Alice's profile

Solution

  1. Step 1: Understand graph database query

    Graph DB queries return nodes and edges; friends of Alice are nodes connected by 'friend' edges.
  2. Step 2: Compare expected outputs

    Key-value pairs or tables are not typical graph DB outputs; JSON document is for document DB.
  3. Final Answer:

    A set of nodes connected to 'Alice' by edges labeled 'friend' -> Option A
  4. Quick Check:

    Graph DB returns connected nodes and edges [OK]
Hint: Graph DB queries return nodes and edges, not tables or JSON [OK]
Common Mistakes:
  • Expecting tabular output from graph DB
  • Confusing document DB JSON with graph DB output
  • Thinking key-value pairs represent graph edges
4. You wrote a query to retrieve data from a column-family NoSQL database but got an error. Which mistake likely caused this?
medium
A. Using nested JSON documents in the query
B. Querying nodes and edges instead of tables
C. Trying to access data by key only without specifying column family
D. Using key-value pairs without keys

Solution

  1. Step 1: Understand column-family DB query requirements

    Column-family DBs require specifying column families to access data properly.
  2. Step 2: Identify error cause

    Accessing data by key alone without column family causes errors; other options relate to different DB types or invalid syntax.
  3. Final Answer:

    Trying to access data by key only without specifying column family -> Option C
  4. Quick Check:

    Column DB needs column family in queries [OK]
Hint: Column DB queries must specify column family [OK]
Common Mistakes:
  • Using document DB JSON syntax in column DB
  • Ignoring column family in queries
  • Confusing graph DB queries with column DB
5. You need to design a social network app that stores users, their posts, and complex friend relationships with recommendations. Which NoSQL database type should you choose and why?
hard
A. Graph database, because it efficiently manages complex relationships
B. Key-value database, because it is fastest for any data
C. Document database, because it handles nested posts well
D. Column database, because it stores large tables efficiently

Solution

  1. Step 1: Analyze app data needs

    The app needs to store users, posts, and complex friend relationships with recommendations.
  2. Step 2: Match database type to needs

    Graph DBs excel at managing complex relationships and traversals, ideal for social networks.
  3. Step 3: Evaluate other options

    Document DB handles nested data but less efficient for relationships; key-value is simple but not relationship-focused; column DB is for wide tables, not relationships.
  4. Final Answer:

    Graph database, because it efficiently manages complex relationships -> Option A
  5. Quick Check:

    Complex relationships = Graph DB [OK]
Hint: Complex relationships? Choose graph DB [OK]
Common Mistakes:
  • Choosing document DB for relationship-heavy data
  • Assuming key-value is best for all speed needs
  • Ignoring graph DB strengths in relationships