Introduction to NoSQL Database
Introduction to NoSQL Database
1. Introduction to NoSQL
1.1 What is NoSQL?
Big Data & Real-Time Web Apps: Handles large volumes of data efficiently.
Flexible Schema: Unlike SQL, NoSQL does not require a fixed schema.
Horizontal Scaling: Easily distributes data across multiple servers (sharding).
High Availability & Fault Tolerance: Many NoSQL databases support replication.
Data Model Tables with fixed schema Flexible (Key-Value, Document, etc.)
Use Cases Complex queries, transactions Big Data, real-time apps, IoT
2. Types of NoSQL Databases
Structure:
Key-value stores are the simplest form of NoSQL databases, where each item is stored
as a key-value pair, similar to a dictionary or hash table. The key is a unique identifier,
and the value can be any type of data (e.g., strings, numbers, JSON, or binary objects).
DB Examples:
Redis – An in-memory key-value store known for its speed, often used for caching.
DynamoDB – A fully managed AWS database that supports high scalability and low-
latency access.
Riak – A distributed key-value store designed for fault tolerance.
Use Cases:
Caching – Storing frequently accessed data to reduce database load (e.g., Redis).
Session Management – Keeping user session data (e.g., shopping cart info).
Real-time Applications – Such as leaderboards or configuration settings.
Structure:
Document databases store data in semi-structured formats like JSON, BSON. Unlike
key-value stores, document databases allow nested structures and support querying
within documents. Each document can have a different schema, providing flexibility.
DB Examples:
MongoDB – A widely used document database with powerful querying and
indexing.
CouchDB – Focuses on ease of use and offline synchronization.
Firebase Firestore – A cloud-based document store with real-time updates.
Use Cases:
Structure:
Instead of storing data in rows (like relational databases), column-family databases
organize data in columns grouped into families. This structure is optimized for reading
large datasets efficiently, especially for analytical queries.
DB Examples:
Use Cases:
Structure:
Graph databases represent data as nodes (entities), edges (relationships), and
properties. This model is ideal for highly interconnected data, allowing efficient
traversal of relationships.
DB Examples:
Neo4j – The most popular graph database with a powerful query language (Cypher).
ArangoDB – A multi-model database supporting graphs, documents, and key-value
storage.
Use Cases:
3.2 Limitations
✖ No Standard Query Language: Each NoSQL DB has its own query method.
✖ Less Mature: Fewer tools and community support compared to SQL.
✖ Eventual Consistency: Some NoSQL DBs sacrifice consistency for speed.
('MacBook Air M2', '{"brand": "Apple", "color": "space gray", "specs": {"chip": "M
2", "RAM": "8GB", "storage": "256GB", "display": "13.6-inch"}}'),
('MacBook Pro 14"', '{"brand": "Apple", "color": "silver", "specs": {"chip": "M3 P
ro", "RAM": "18GB", "storage": "512GB", "display": "14.2-inch", "ports": ["HDMI",
"SDXC"]}}'),
Extracting Fields
JSONB-Specific Operators
Note: The UNNEST function in PostgreSQL is used to expand an array into a set of rows, effe
ctively "flattening" the array so you can work with each element individually.
-- Find users with exactly 2 tags
SELECT name FROM users WHERE array_length(tags, 1) = 2;
Query Simple
SQL + JSON operators MongoDB Query Language
Language commands
In-Memory
Scalability Vertical + Read Replicas Horizontal Sharding
Cluster
Best For Hybrid SQL/NoSQL needs Pure document storage Caching, Queues