Introduction to NoSQL Data Models
Before we start about Data Models, Let’s first understand what NoSQL means. NoSQL means not the only SQL which means we are going to retrieve and store data from non-relational databases. Now let’s see what data model is? A data model defines the logical structure of DBMS. This basically means that it tells us how data is connected to each other, relationships between various entities and how they are processed. Data modeling techniques are different for both relational and non-relational databases. The main difference is NoSQL data models have more application-specific queries as compared to SQL.
Syntax with parameters
The Syntax for writing a NoSQL query is given with an example. In this example, we are going to retrieve the name and age of all employees with designation as Manager.
{
"object": "employee",
"q": {
"designation" : " Manager"
},
"fields": ["name", "age"]
}
In the above example we have used the JSON form to write a query “object” keyword is used to assign a table name, the keyword “q” is used as a WHERE condition. In our case the where a condition has to be applied over the designation as we want only employees whose designation is the manager. The key “field” is the names of columns we want to retrieve based on the condition in “q”. In our case, the columns are name and age.
The above NoSQL query if converted to SQL will look as below:
SELECT name, age
FROM employee
WHERE designation =’ manager’;
The shortest query that we can write is a normal select query in NoSQL is as follows:
{
"object": "String",
"q": "Expression"
}
The above query is a normal select query.
Types of NoSQL Data Models
Now let’s learn about the different types of NoSQL data models.
In general, there are four different types of data models in NoSQL. They are as follows and we will discuss them one by one.
Now let’s go through them one by one.
1. Key-value Store
- As the name suggests the Key-value store simply uses the key value to store data in the database. The key in the key-value pair must be unique. The rules set for what the key can be the length for the size of the key depends on the database to the database. For example in Redis, the maximum size for Key is 512mb. Even the empty string is a valid key.
- The size of the key is important here as a long key can cause performance issues whereas a too short a key can cause readability issues. The value in the key-value pair can be anything from a String to an image. You can also specify the data type of the value here.
- The key-value database model can be useful for storing data on Ecommerce like product categories, product details, etc. These are extensively used in big data analytics. We can even store complete URLs as the URL name can be the key and the actual URL as value. Examples of databases applying Key-Value pairs are Oracle NoSQL database and Redis.
2. Document-Based Store NoSQL
- In this type of database, the record and its associated data are stored in a single document. So this model is not completely unstructured but it is a kind of Semi-structured data.
- The difference between a document and Key value pair is that in document type storage is that in this type some kind of encoding is provided while storing the data in documents, It can be XML encoding or JSON encoding.
- The below example shows a document that can be stored in a document database but with a different encoding. Let’s look at the XML example.
<employee>
<employeename>Srikanth</<artistname>
<designation> Engineer</designation>
<DOJ>Febuary</DOJ>
</employee >
- The difference between conventional databases and document-based databases is that data here is not stored in tables like conventional databases but are stored in documents.
- The examples of databases using the above data model are MongoDB and Couchbase. These types of databases are used extensively especially in big data analysis.
3. Column Based Store
- In this type of database, the focus is on columns rather than rows as data is stored in columns instead of rows which is the case with most relational databases. Since data is stored in cells grouped in columns so all read-write is done using columns, not rows.
- The interesting question arises is that why use columns rather than rows? The answer to this question is that when you store data in columns you can do a fast search and fast retrieval and aggregation because it stores all the cells of a column as a continuous entry which then allows faster access.
- As an example, if we want to query titles from million articles, it will be easy to get in the column-based data model as with one disk entry we will get the titles of the article easily whereas in relational databases it has to get over to each location to get the titles. Examples of Column based store databases is HBase, Big Table, Cassandra.
4. Graph-Based Store
- As the name suggests graphical representation is used instead of tables or columns representation. The important feature of this type of data model is the presence of nodes and edges. The two nodes, for example, are connected with some relationships and the relationship here is represented by edges.
- Also, you can efficiently transform data from one model to another using this Graph-based NoSQL data model. There are two commonly used graph-based databases which are InfoGrid and Infinite Graph. InfoGrid also offers two kinds of graph databases like MeshBase and NetMeshbase which users can choose depends on the requirements of the user.
Conclusion
In this article, we have discussed the NoSQL database and different types of NoSQL models and discuss those models individually. The different types of databases available in each type of data model. NoSQL database popularity is growing with each passing day because of its speed and efficiency.
Recommended Articles
This is a guide to NoSQL Data Models. Here we discuss the Types of NoSQL Data Models and the Syntax with parameters and explanations. You can also go through our other suggested articles to learn more–