NoSQL Vs SQL Databases Explained
NoSQL Vs SQL Databases Explained
NoSQL databases (AKA "not only SQL") store data di�erently than
relational tables. NoSQL databases come in a variety of types based
on their data model. The main types are document, key-value, wide-
column, and graph. They provide �exible schemas and scale easily
with large amounts of big data and high user loads.
In this article, you'll learn what a NoSQL database is, why (and when!)
you should use one, and how to get started.
Table of contents
Document-oriented databases
A document-oriented database stores data in documents similar to
JSON (JavaScript Object Notation) objects. Each document contains
pairs of �elds and values. The values can typically be a variety of
types, including things like strings, numbers, booleans, arrays, or even
other objects. A document database o�ers a �exible data model,
much suited for semi-structured and typically unstructured data sets.
They also support nested structures, making it easy to represent
complex relationships or hierarchical data.
1 {
{
2 "_id": "12345",
4 "email": "[email protected]",
5 "address": {
9 "zip": "123456"
10 },
12 }
Key-value databases
A key-value store is a simpler type of database where each item
contains keys and values. Each key is unique and associated with a
single value. They are used for caching and session management and
provide high performance in reads and writes because they tend to
store things in memory. Examples are Amazon DynamoDB and Redis. A
simple view of data stored in a key-value database is given below:
1 Key: user:12345
Graph databases
A graph database stores data in the form of nodes and edges. Nodes
A graph database stores data in the form of nodes and edges. Nodes
typically store information about people, places, and things (like
nouns), while edges store information about the relationships between
the nodes. They work well for highly connected data, where the
relationships or pa�erns may not be very obvious initially. Examples of
graph databases are Neo4J and Amazon Neptune. MongoDB also
provides graph traversal capabilities using the $graphLookup stage of
the aggregation pipeline. Below is an example of how data is stored:
Multi-model databases
Multi-model databases support more than one type of NoSQL data
model so that developers can choose based on their application
requirements. These databases have a uni�ed database engine that
can handle multiple data models within a database instance. Examples
are CosmosDB and ArangoDB.
• Distributed computing
• Scaling
• Flexible schemas and rich query language
• Ease of use for developers
• Partition tolerance
• High availability
BASE compliance
NoSQL databases are BASE compliant, i.e., basic availability so� state
eventual consistency. Basic availability refers to the ability of the
system to tolerate a partial failure (like a loss of a node). So� state
means that the system allows temporary inconsistencies before
eventually achieving consistency automatically over time. BASE
compliance ensures high availability, faster data processing,
scalability, and �exibility. However, MongoDB can also be con�gured
to provide multi-document ACID compliance.
The data model we design for a NoSQL database will depend on the
type of NoSQL database we choose. Let's consider how to store the
same information about a user and their hobbies in a
document database like MongoDB.
Data modeling
NoSQL: Data models vary based on the type of NoSQL database used
— for example, key-value, document, graph, and wide-column — making
the model suitable for semi-structured and unstructured data.
Schema
NoSQL: It provides a �exible schema where each set of documents/
row-column/key-value pairs can contain di�erent types of data. It’s
easier to change schema, if required, due to the �exibility.
RDBMS: This is a �xed schema where every row should contain the
same prede�ned column types. It is di�cult to change the schema
once data is stored.
Query language
NoSQL: It varies based on the type of NoSQL database used. For
example, MongoDB has MQL, and Neo4J uses Cypher.
Scalability
NoSQL: NoSQL is designed for vertical and horizontal scaling.
Data relationships
NoSQL: Relationships can be nested, explicit, or implicit.
Transaction type
NoSQL: Transactions are either ACID- or BASE-compliant.
Performance
NoSQL: NoSQL is suitable for real-time processing, big data analytics,
and distributed environments.
and distributed environments.
Data consistency
NoSQL: This o�ers high data consistency.
Distributed computing
NoSQL: One of the main reasons to introduce NoSQL was for
distributed computing, and NoSQL databases support distributed data
storage, vertical and horizontal scaling through sharding, replication,
and clustering.
Fault tolerance
NoSQL: NoSQL has built-in fault tolerance and high availability due to
data replication.
Data partitioning
NoSQL: It’s done through sharding and replication.
Note that the way data is modeled in NoSQL databases can eliminate
the need for multi-record transactions in many use cases. Consider the
earlier example where we stored information about a user and their
hobbies in both a relational model and a document store. To ensure
information about a user and their hobbies was updated together in a
relational database, we'd need to use a transaction to update records
in two tables. To do the same in a document store, we could update a
single document — no multi-record transaction required.
When you are ready to try more advanced queries that aggregate your
data, create an aggregation pipeline. The aggregation framework is
an incredibly powerful tool for analyzing your data. To learn more, take
the free MongoDB University Course
M121 The MongoDB Aggregation Framework.
When you want to visualize your data, check out MongoDB Charts.
Charts is the easiest way to visualize data stored in Atlas and Atlas
Data Lake. Charts allow you to create dashboards that are �lled with
visualizations of your data.
Summary
NoSQL databases provide a variety of bene�ts, including �exible data
models, horizontal scaling, lightning-fast queries, and ease of use for
developers. NoSQL databases come in a variety of types, including
document stores, key-values databases, wide-column stores, graph
databases, and multi-model databases.
Excited to learn more now that you have your own Atlas account?
Head over to MongoDB University where you can get free online
training from MongoDB engineers and earn a MongoDB certi�cation.
training from MongoDB engineers and earn a MongoDB certi�cation.
The Quickstarts are another great place to begin; they will get you up
and running quickly with your favorite programming language.
FAQs
Is JSON a NoSQL?
Learn More
• MongoDB Compatibility
• MongoDB Basics
• Learn About Databases
• Languages compatible with MongoDB