Practice
1. Which of the following best describes a key-value NoSQL database?
easy
Solution
Step 1: Understand key-value database structure
Key-value databases store data as unique keys linked to values, like a dictionary.Step 2: Compare with other database types
Relational databases use tables; graph databases use nodes and edges; key-value is simpler with pairs.Final Answer:
Stores data as pairs of keys and their associated values -> Option AQuick Check:
Key-value = key-value pairs [OK]
Hint: Key-value means simple pairs: key and its value [OK]
Common Mistakes:
- Confusing key-value with relational tables
- Thinking key-value uses SQL queries
- Mixing key-value with graph database concepts
2. Which of the following is the correct way to represent a document in a document-based NoSQL database?
easy
Solution
Step 1: Identify document format in NoSQL
Document databases use JSON-like objects with key-value pairs inside braces {}.Step 2: Check each option's format
{"name": "Alice", "age": 30}uses JSON object syntax; others use tuples, lists, or invalid syntax.Final Answer:
{"name": "Alice", "age": 30} -> Option AQuick Check:
Document = JSON object format [OK]
Hint: Documents look like JSON objects with braces {} [OK]
Common Mistakes:
- Using parentheses instead of braces
- Confusing lists with documents
- Writing invalid key-value syntax
3. Given a graph database storing people and their friendships, which query result would you expect from:
MATCH (p:Person)-[:FRIEND]->(f:Person) RETURN p.name, f.name?medium
Solution
Step 1: Understand the MATCH pattern
The query finds nodes labeled Person connected by FRIEND relationships from p to f.Step 2: Interpret the RETURN clause
It returns the names of p and f, showing pairs where p is friends with f.Final Answer:
Pairs of person names where the first is friends with the second -> Option DQuick Check:
Graph query returns connected pairs [OK]
Hint: MATCH with relationship returns connected node pairs [OK]
Common Mistakes:
- Thinking it returns all persons regardless of friendship
- Expecting counts instead of pairs
- Confusing direction of FRIEND relationship
4. You wrote this query for a column-family NoSQL database:
SELECT name, age FROM users WHERE age > 25. It returns an error. What is the likely problem?medium
Solution
Step 1: Recall column-family query style
Column-family NoSQL databases like Cassandra use CQL, similar but not always supporting full SQL syntax.Step 2: Identify syntax mismatch
Some column-family databases require specific query formats; plain SQL SELECT with WHERE may cause errors.Final Answer:
Column-family databases do not use SQL syntax like SELECT -> Option CQuick Check:
Column-family ≠ standard SQL [OK]
Hint: Column-family queries differ from standard SQL [OK]
Common Mistakes:
- Assuming all NoSQL use SQL syntax
- Ignoring database-specific query language
- Blaming typos without checking syntax
5. You want to model a social network with users and their followers using a NoSQL database. Which model is best suited to efficiently represent and query these relationships?
hard
Solution
Step 1: Understand social network data needs
Social networks have complex, connected data with users linked by follower relationships.Step 2: Match data needs to NoSQL model
Graph databases excel at storing and querying connected nodes and edges efficiently.Step 3: Compare other models
Key-value and document stores handle data but less efficient for complex relationships; column-family is for wide tables.Final Answer:
Graph database, because it stores nodes and edges representing users and follower links -> Option BQuick Check:
Connected data = Graph database [OK]
Hint: Use graph DB for connected user relationships [OK]
Common Mistakes:
- Choosing key-value for relationship queries
- Assuming document DB handles connections best
- Ignoring graph model strengths
