A non-relational database does not use tables, rows, columns, primary keys, relationships, or schemas. Instead, a
NoSQL
database stores data using various storage models, depending on the type of data stored.Due to the lack of a defined structure for the database,
NoSQL
databases are very scalable and flexible. When dealing with datasets that are not very well defined and structured, aNoSQL
database would be the best choice for storing our data.There are 4 common storage models for
NoSQL
databases:- Key-Value
- Document-Based
- Wide-Column
- Graph
Each of the above models has a different way of storing data. For example, the
Key-Value
model usually stores data inJSON
orXML
, and has a key for each pair, storing all of its data as its value:
date
content] box2[id
date
content] box3[id
date
content] end box1 --> Key1[Key] box1 --> Value1[Value] box2 --> Key2[Key] box2 --> Value2[Value] box3 --> Key3[Key] box3 --> Value3[Value]
- The above example can be represented using
JSON
as follows:
{
"100001": {
"date": "01-01-2021",
"content": "Welcome to this web application."
},
"100002": {
"date": "02-01-2021",
"content": "This is the first post on this web app."
},
"100003": {
"date": "02-01-2021",
"content": "Reminder: Tomorrow is the ..."
}
}
It looks similar to a dictionary/map/key-value pair in languages like
Python
orPHP
‘i.e.{'key':'value'}
’, where thekey
is usually a string, thevalue
can be a string, dictionary, or any class object.The
Document-Based
model stores data in complexJSON
objects and each object has certain meta-data while storing the rest of the data similarly to theKey-Value
model.Some of the most common
NoSQL
databases include:
Type | Description |
---|---|
MongoDB | The most common NoSQL database. It is free and open-source, uses the Document-Based model, and stores data in JSON objects |
ElasticSearch | Another free and open-source NoSQL database. It is optimized for storing and analyzing huge datasets. As its name suggests, searching for data within this database is very fast and efficient |
Apache Cassandra | Also free and open-source. It is very scalable and is optimized for gracefully handling faulty values |
- Other common
NoSQL
databases include:Redis
,Neo4j
,CouchDB
, andAmazon DynamoDB
.