Module 1 Introduction
Module 1 Introduction
Introduction to NoSQL
In the world of databases, there are many different ways to organize and store data. At this point, we are
familiar with the concept of relational databases that store data in rows, form relationships between the
tables, and query the data using SQL. However, a new type of database, NoSQL, started to rise in popularity
in the early 21st century.
NoSQL is short for “not-only SQL”, but is also commonly called “non-relational” or “non-SQL”. Any
database technology that stores data differently from relational databases can be categorized as a NoSQL
database.
What Is NoSQL?
NoSQL, which stands for "Not only SQL," refers to a diverse set of database technologies that differ from
traditional relational databases (SQL databases) in how they store and retrieve data. NoSQL databases are
designed to handle large volumes of unstructured, semi-structur ed, and structured data more efficiently and
flexibly than traditional databases. They are particularly suited for applications where high performance,
scalability, and flexibility are crucial, such as real-time web applications, big data analytics, content
management systems, and IoT (Internet of Things) platforms.
Why NoSQL databases are required.
NoSQL databases are often chosen over traditional relational databases (SQL databases) for several reasons,
depending on the specific needs and characteristics of the application or system:
1. Scalability: NoSQL databases are designed to horizontally scale out across many servers, which makes
them suitable for handling large amounts of data and high traffic levels.
2. Flexibility and Schema-less Design: Unlike relational databases, which require a predefined schema,
NoSQL databases typically have a flexible schema or are schema-less. This means they can handle semi-
structured or unstructured data more easily.
3. High Performance: NoSQL databases are optimized for specific data models and access patterns. They
can often outperform relational databases for certain types of queries, especially those involving large
volumes of data or those that can be distributed across nodes.
4. Support for Distributed Computing: Many NoSQL databases are designed with distributed computing in
mind, making them suitable for cloud-based deployments and environments where data needs to be
available across different regions or data centers.
5. Specialized Data Models: NoSQL databases offer different data models (such as key-value, document,
column-family, or graph databases), each suited for different types of data and use cases.
6. Horizontal Scaling and Fault Tolerance: NoSQL databases typically provide built-in mechanisms for
replication and partitioning that ensure high availability and fault tolerance. This is crucial for applications
that require continuous operation even in the event of hardware failures or network issues.
7. Cost-effectiveness: NoSQL databases can often be more cost-effective than traditional relational
databases, especially when dealing with large-scale data storage and processing. They can run on
commodity hardware and often require less upfront investment in terms of licensing and infrastructure.
8. Use Cases: NoSQL databases are well-suited for certain use cases such as real-time web applications, IoT
data storage and retrieval, caching, session management, and analytics where fast read and write operations
are critical.
Types of NoSQL Database
A database is a collection of structured data or information which is stored in a computer system and can be
accessed easily. A database is usually managed by a Database Management System (DBMS).
NoSQL is a non-relational database that is used to store the data in the nontabular form. NoSQL stands for
Not only SQL. The main types are documents, key-value, wide-column, and graphs.
Document-Based Database:
The document-based database is a nonrelational database. Instead of storing the data in rows and columns
(tables), it uses the documents to store the data in the database. A document database stores data in JSON,
BSON, or XML documents.
Documents can be stored and retrieved in a form that is much closer to the data objects used in applications
which means less translation is required to use these data in the applications. In the Document database, the
particular elements can be accessed by using the index value that is assigned for faster querying.
Key-Value Stores:
A key-value store is a nonrelational database. The simplest form of a NoSQL database is a key-value store.
Every data element in the database is stored in key-value pairs. The data can be retrieved by using a unique
key allotted to each element in the database. The values can be simple data types like strings and numbers or
complex objects.
A key-value store is like a relational database with only two columns which is the key and the value.
Key features of the key-value store:
Simplicity.
Scalability.
Speed.
Column Oriented Databases:
A column-oriented database is a non-relational database that stores the data in columns instead of rows. That
means when we want to run analytics on a small number of columns, you can read those columns directly
without consuming memory with the unwanted data.
Columnar databases are designed to read data more efficiently and retrieve the data with greater speed. A
columnar database is used to store a large amount of data. Key features of columnar oriented database:
Scalability.
Compression.
Very responsive.
Graph-Based databases:
Graph-based databases focus on the relationship between the elements. It stores the data in the form of nodes
in the database. The connections between the nodes are called links or relationships.
Key features of graph database:
In a graph-based database, it is easy to identify the relationship between the data by using the links.
The Query’s output is real-time results.
The speed depends upon the number of relationships among the database elements.
Updating data is also easy, as adding a new node or edge to a graph database is a straightforward task
that does not require sign-ificant schema changes.
SQL NoSQL
Multi-Record
Most do not support multi-record ACID transactions. However,
ACID Supported
some — like MongoDB — do.
Transactions
Data to Object Requires ORM (object- Many do not require ORMs. MongoDB documents map directly to
Mapping relational mapping) data structures in most popular programming languages.
CAP Theorem
The CAP Theorem, also known as Brewer's Theorem, states that in a distributed data store, it is impossible
to simultaneously achieve all three of the following guarantees:
1. Consistency: Every read receives the most recent write or an error.
2. Availability: Every request receives a response, without guaranteeing that it contains the most recent
write.
3. Partition tolerance: The system continues to operate despite network partitions (communication failures)
between nodes.
According to the CAP Theorem, a distributed system can guarantee at most two out of these three properties
at any given time. Therefore, database systems must make trade-offs in their design and implementation
based on the specific needs of their applications and environments.
Installation
Step 1 :-
- Check for the mount point with good amount of space using command "df -h"
- Here in my case there is 3.6GB of space available in '/' mount point, so i am going to install my software in
'/' mount point.
Step 2 :-
- Now we will create required directories for software installations.
- As you can we have created mymongo directory and under mymongo directory we have created two more
directories which was log and data.
Step 3 :-
- In the next step we will copy the link of software from mongodb website.
https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-ubuntu2204-6.0.15.tgz
- In my case i have selected platform ubuntu 22.04 x64 because i am using ubuntu os 22.04 release.
Step 4 :-
- Now we will paste that copied link in our terminal using command "wget"
root@you-VirtualBox: /mymongo# wget https://fastdl.mongodb.org/linux/mongodb-linux-x86_64-
ubuntu2204-6.0.1 5.tgz
- to check whether services has started or not execute command "ps -ef | grep mongo" in duplicate terminal.
- until here we have successfully installed our mongodb software.
Step 8 :-
- Now we will download the mongodb shell to use our database. for that we will copy the link of
mongodb shell from website.
https://downloads.mongodb.com/compass/mongosh-2.2.5-linux-x64.tgz
- As we can see mongodb services has been started successfully. now we can connect to our database.