Lesson 3_Non-Relational Database Types
Lesson 3_Non-Relational Database Types
Non-Relational Database
Types
Google slide deck available here
There are four main types of non-relational databases: key/value, graph, column, and
document, and we’ll investigate each in this lesson.
Structure
Strength
Key/Value Database
● Simple data model.
Key-value databases use a very simple schema: a unique key is paired with a
collection of values, where the values can be anything from a string to a large binary
object.
One way that databases using this structure gain in performance is that there are no
complex queries. The system knows on which server the data is located and sends
the request to just that server.
Example: Redis is one of the most popular examples of a key/value store database. .
Key/Value: Example
Key Value
Age 40
Strength
Graph databases are another type within the non-relational family of databases. A
popular example of a graph database being used today is Neo4J.
They have been designed to deal with problems around relationships with and
focuses on connected data. This type of model does capture the richness of the
relationships, however many problems are not naturally modelled as connected data
or relationship problems. This makes this database well matched to these problems
but as these are niche, it does not have a wider or broader applicability to other
problems.
This databases stores information as a collection of nodes and edges, where the
edges represent the relationships between the nodes.
Storing the relationships between data means that related data can often be retrieved
in a single operation. The concept of relationships between data and this
interconnectedness is the key principle behind this type of non-relational database.
This approach counters the approach required in SQL/Relational Databases where many
joins on several attributes in a number of tables would often be required to retrieve these
kinds of relations in the data.
:li
ke
d
Sherlock
Holmes
ress
s
Post nd
e :fri
1 :fri h wi ends
:add
:p
os wit th
te
d
:friends with
John Irene
Watson Adler
:p
ed
os
:p
st
te
os
d
:like
:po
te
d
Post Post
2 Post
3 1
Strengths
The structure of the column data is flexible and can vary from row to row. Associated
with storing large amounts of data: billions of rows with millions of columns
This does not necessarily require a separate database and can be implemented as
indexes on existing data structures to add this type of functionality to a database.
Column Oriented Example
Here we see an example of what data might look like in a column-oriented database.
Though at first glance it might seem similar to the known relational tabular format, it is
very different in that the data is sorted via column IDs. Therefore the relationships
between data are identified via the column key.
Structure
● Polymorphic data models
Strengths
● Obvious relationships using
embedded arrays and
documents
Document Database
● No complex mapping
Document databases, such as MongoDB, store data in a single document which can
have different shapes within the single collection or table that stores the documents.
The document is a close analogy to the object in object oriented programming and
provides a clear natural representation of a ‘thing’ and it’s data.
This clear representation often means that there is no requirement for object mapping
between the database and the application/programming language. The document is
often the exact match for the object that the programmer wishes to use. The flexibility
of the document to hold many shapes or multiple parallel schemas at any point in time
gives great flexibility for modeling with documents when compared to relational
database tables.
Document Model Example
{
"_id": {
ObjectId("5ef2d4b45b7f11b6d7a" "_id":
), ObjectId("6ef8d4b32c9f12b6d4a")
"user_id": "Sherlock ,
Holmes", "user_id": "John Watson",
"age": 40, "age": 45,
"address": "address":
{ {
“Country: “England” “Country: “England”
“City”: “London”, “City”: “London”,
“Street”: “221B Baker “Street”: “221B Baker
St.” St.”
}, },
“Hobbies”:[ violin, “Medical license”: “Active”
crime-solving ] }
}
The key thing to understand about the document model is that data that is accessed
together is stored together. It is also important to note that just because one
document has one field does not mean another related document has to have the
same field when stored together. We will discuss this more in the lesson when we talk
about collections.
The Document Model
Due to the fact that the document model implements data structures using
programming languages, it is the preferred model by developers as it most closely
matches the way they think and work already.
We will take a closer look at the document model and understand how it functions.
Quiz
Quiz
B. Graph
C. Column-oriented or wide-column
D. Document
E. Data Lake
Quiz
Which of the following are types of non-relational databases? More
than one answer choice can be correct.
A. Key/Value
B. Graph
C. Column-oriented or wide-column
D. Document
E. Data Lake
C. Column-oriented or wide-column
D. Document
E. Data Lake
C. Column-oriented or wide-column
D. Document
E. Data Lake
D. Document
E. Data Lake
C. Column-oriented or wide-column
D. Document
E. Data Lake
MongoDB University has free self-paced Sign up for the MongoDB Student Pack to
courses and labs ranging from beginner receive $50 in Atlas credits and free
to advanced levels. certification!
This concludes the material for this lesson. However, there are many more ways to
learn about MongoDB and non-relational databases, and they are all free! Check out
MongoDB’s University page to find free courses that go into more depth about
everything MongoDB and non-relational. For students and educators alike, MongoDB
for Academia is here to offer support in many forms. Check out our educator
resources and join the Educator Community. Students can receive $50 in Atlas credits
and free certification through the Github Student Developer Pack.