No SQL PR 1 & 2
No SQL PR 1 & 2
Laboratory Manual
Enrolment No
Name
Branch
Academic Term
Institute
Laboratory Manual
Institute’s Vision:
Institute’s Mission:
Department’s Vision:
Department’s Mission:
Certificate
Place: …………………….….
Date: …………………………
Each practical session has been thoughtfully designed to serve as a tool for developing
and enhancing industry-relevant competencies in every student. Recognizing the
limitations of traditional teaching methods, especially in developing psychomotor skills,
this lab manual shifts the focus from the outdated practice of conducting practicals
solely for concept and theory verification. Instead, it prioritizes industry-defined
outcomes, providing students with an opportunity to read and understand procedures
in advance. This allows them to grasp the magnitude of the experiment before its actual
execution, fostering predetermined outcomes.
Every experiment in this manual commences with a focus on competencies, industry-
relevant skills, course outcomes, and practical outcomes, serving as crucial benchmarks
for the practical work. Clear guidelines on safety and necessary precautions are
provided to ensure the well-being of students during experiments. The manual also
equips lecturers with instructions for facilitating student-centered lab activities,
emphasizing the arrangement and management of resources for effective practical
sessions. Additionally, it outlines the assessment criteria through provided rubrics,
offering insights into the evaluation process.
In the context of NoSQL databases, this lab manual provides an introduction to the
diverse types of NoSQL databases, with a specific focus on MongoDB, Cassandra, Neo4j
Graph Databases, and Redis. The content covers installation procedures, basic CRUD
operations, data modeling, and simple queries for each database. Students are guided to
apply their knowledge in practical scenarios, enabling them to develop solutions for
various problems using the distinctive features of each NoSQL database. As we strive to
present a comprehensive lab manual, we welcome and appreciate any suggestions for
improvement.
Programme Outcomes (POs):
Following programme outcomes are expected to be achieved through the practical of the
course:
Marks
Sr. No Experiment/Practical Outcome Page Date Sign
(10)
A. Objective
To provide students with a comprehensive understanding of NoSQL databases, their
underlying principles, and the various types available. It focuses on the fundamental CAP
theorem in distributed systems and delves into the unique characteristics of various NoSQL
databases. Ultimately, the practical aims to empower students to make informed decisions in
selecting a database solution aligned with specific project needs.
- Identify and analyze specific engineering challenges related to NoSQL databases using
established methodologies and principles.
- Develop solutions for well-defined technical problems in the context of NoSQL databases,
contributing to the design of effective data management systems.
- Apply modern engineering tools and testing techniques to assess and validate the
performance of NoSQL databases, ensuring adherence to standard practices.
- Demonstrate the ability to analyze personal learning needs and engage in lifelong
learning, particularly in the evolving landscape of NoSQL databases and related technologies.
P a g e 10
Introduction to NoSQL (4360704)
Name: Raidan Ujef Enrolment: 226010307098 Batch: CO3
C. Competency and Practical Skills
1. NoSQL Fundamentals:
- Develop skills to make informed choices by exploring real-world use cases, understanding
factors influencing database selection, and conducting comparativeanalyses.
P a g e 11
Introduction to NoSQL (4360704)
Name: Raidan Ujef Enrolment: 226010307098 Batch: CO3
G. Prerequisite Theory
Introduction to NoSQL Databases
NoSQL databases, or "Not Only SQL," represent a diverse category of database management
systems designed to address the limitations of traditional relational databases.
NoSQL databases are defined as non-tabular databases that handle data storage differently as
compared to relational tables. Unlike SQL databases, NoSQL databases are schema- less and
provide a more flexible data model, allowing for the storage and retrieval of large volumes of
unstructured or semi-structured data. They are particularly well-suited for handling dynamic
and rapidly evolving data in distributed and scalable environments.
NoSQL databases are gaining traction for real-time cloud, web, and big data applications due to
their key features:
- NoSQL supports various data models, allowing flexibility in handling unstructured, semi-
structured, and structured data.
- Ideal for Agile development, as it accommodates different data models without the need
for separate databases.
- Advanced NoSQL databases facilitate global data distribution by operating across multiple
cloud regions and data centers.
4. Minimal Downtime:
- Serverless architecture and data replication across nodes ensure business continuity, with
alternative nodes providing access in case of a malfunction.
in cloud and web applications with a broad and rapidly growing user base. Its flexibility,
multi-modality, scalability, availability, and global distribution make it ideal for
certain use cases. However, both database types can coexist and complement each other,
allowing organizations to leverage the strengths of each based on their requirements.
1. Document-oriented Databases:
2. Key-Value Stores:
3. Column-family Stores:
4. Graph Databases:
CAP Theorem
The CAP theorem, originally known as the CAP
principle, illuminates the inherent trade-offs in
designing distributed systems with replication. It
highlights the challenge of simultaneouslyachieving
consistency, availability, and partition tolerance in
such systems
1. Consistency (C):
- All nodes in the system see thesame data at
the same time.
2. Availability (A):
- Every request receives a response, without
guarantee that it contains the most recent
version of the information.
P a g e 13
Introduction to NoSQL (4360704)
Name: Raidan Ujef Enrolment: 226010307098 Batch: CO3
The CAP theorem asserts that distributed databases can prioritize at most two of these three
properties. Database systems fall into categories based on their priorities:
It's crucial to note that database systems may exhibit different behaviors based on
configurations and settings, influencing their consistency, availability, and partition tolerance.
Even in the case of specialized databases like Neo4j, which prioritizes consistency and
partition tolerance over availability, the CAP theorem remains relevant. In situations of
network partition or failure, Neo4j sacrifices availability to maintain consistency.
System architects must make trade-offs based on the application's requirements and the
characteristics of the underlying NoSQL database.
P a g e 14
Introduction to NoSQL (4360704)
Name: Raidan Ujef Enrolment: 226010307098 Batch: CO3
-Scalability Requirements: Consider the need for horizontal scalability and how well the
database can distribute data across multiple nodes.
- Consistency and Availability Needs: Assess the trade-offs between consistency and
availability based on the application's requirements.
- Use Case Characteristics: Tailor the choice of database to the specific demands of the
application, such as read and write patterns, data complexity, and relationships.
In conclusion, understanding the nuances of NoSQL databases, their types, trade-offs, and
specific use cases is crucial for making informed decisions in selecting the right database
solution for diverse applications.
H. Resources/Equipment Required
1. Internet Connectivity:
- Reliable internet connectivity is essential for accessing online resources, databases, and
relevant documentation.
P a g e 15
Introduction to NoSQL (4360704)
Name: Raidan Ujef Enrolment: 226010307098 Batch: CO3
2. Documentation and Learning Materials:
4. Which NoSQL database is best suited for managing and querying interconnected data,such as
social networks?
a) MongoDB c) Neo4j
b) Cassandra d) Redis
5. What type of data model does a Key-Value Store NoSQL database follow?
a) Tabular c) Graph
b) Document-oriented d) Key-Value
a) MongoDB c) Neo4j
b) Cassandra d) Redis
P a g e 16
Introduction to NoSQL (4360704)
Name: Raidan Ujef Enrolment: 226010307098 Batch: CO3
8. Which factor is crucial in deciding the appropriate NoSQL database for an application?
J. References Links
1. https://www.spiceworks.com/tech/artificial-intelligence/articles/what-is-nosql/
2. https://www.geeksforgeeks.org/the-cap-theorem-in-dbms/
3. https://www.mongodb.com/nosql-explained
4. https://www.couchbase.com/resources/why-nosql/
5. https://www.guru99.com/nosql-tutorial.html
K. Assessment Rubrics
Needs
Criteria Excellent (10) Good (7) Satisfactory
Improvement Mark
(5) s
(3)
Demonstrates a
profound Shows a Displays a Demonstrates
Understanding understanding of basic limited
of NoSQL strong grasp of
NoSQL databases, NoSQL understandin comprehension
Concepts accurately defining fundamentals. gof NoSQL of NoSQL
key concepts and concepts. databases.
types.
Accurately identifies
Identification Identifies and Identifies
and explains Struggles to
of NoSQL explains basic types of identify NoSQL
various types of
Database multiple types NoSQL
NoSQL databases, database types.
Types of NoSQL databases.
highlighting their
databases.
characteristics.
Applies NoSQL
Applies Attempts to Limited
Knowledge concepts effectively
NoSQL apply NoSQL application of
Application in to provide relevant concepts to NoSQL
Examples examples of each concepts in
provide examples. concepts in
database type
examples. examples.
discussed.
Average Marks
A. Objective
Familiarize students with MongoDB through an introduction to its features and advantages,
followed by hands-on experience installing and connecting to the database.
2. Problem Analysis:
3. Design/Development of Solutions:
- Design solutions for well-defined technical problems encountered during the installation
and connection processes in MongoDB.
- Utilize appropriate engineering tools to conduct experiments and tests during the
MongoDB installation, ensuring proficiency in modern database technologies.
6. Project Management:
- Demonstrate project management skills while handling the installation of MongoDB, either
individually or as part of a team, and effectively communicate progress.
7. Life-Long Learning:
- Exhibit the ability to adapt and engage in continuous learning, updating skills to match
technological changes in the field of database management, particularly MongoDB.
P a g e 19
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
2. Problem-Solving:
- Apply analytical skills to troubleshoot and resolve issues related to MongoDB installation
and connectivity.
4. Adaptability:
G. Prerequisite Theory
Overview of MongoDB
P a g e 20
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
Data arrives from one or few locations. Data arrives from many locations.
It supports complex transactions. It supports simple transactions.
It has single point of failure. No single point of failure.
It handles data in less volume. It handles data in high volume.
Transactions written in one location. Transactions written in many locations.
support ACID properties compliance doesn’t support ACID properties
Its difficult to make changes in database once itis Enables easy and frequent changes to
defined database
schema is mandatory to store the data schema design is not required
Deployed in vertical fashion. Deployed in Horizontal fashion.
BSON is a binary encoded Javascript Object Notation (JSON)—a textual object notation
widely used to transmit and store data across web based applications. JSON is easier to
understand as it is human-readable, but compared to BSON, it supports fewer data types.
This format optimizes data storage and retrieval, ensuring efficiency in MongoDB's
operations. Key aspects of BSON include:
1. Binary Encoding:
2. Data Types:
BSON supports a rich set of data types, including strings, integers, floating-point numbers,
arrays, and nested documents. This versatility allows MongoDB to handle diverse and
complex data structures, accommodating the dynamic nature of modern applications.
3. Efficient Storage:
The binary nature of BSON enhances data storage efficiency by eliminating the need for
textual parsing. This results in smaller document sizes, reducing I/O operations and
improving overall performance, especially in scenarios with large datasets.
BSON introduces additional data types not found in standard JSON, such as Date and
Binary. These extensions enhance MongoDB's ability to represent diverse information,
including date and time values and binary data like images or multimedia content.
BSON's structure aligns with MongoDB's query language and indexing capabilities,
enabling efficient searching and retrieval of data. MongoDB can leverage BSON's binary
format to accelerate query execution and optimize the performance of read and write
operations.
Understanding BSON is essential for MongoDB developers, as it forms the foundation for
storing and processing data within the database. Its binary representation contributes to
MongoDB's speed, flexibility, and scalability, making it a key component in the success of
MongoDB as a NoSQL database solution.
MongoDB is well-suited for CMS applications where content structures can vary widely. Its
flexible document-oriented model allows developers to adapt to changing content
requirements without compromising performance. MongoDB's ability to handle large volumes
of unstructured data makes it an ideal choice for storing and retrieving diverse content types
efficiently.
2. Real-time Analytics:
In scenarios requiring real-time data analysis, MongoDB excels by providing fast read and
write operations. Its document-oriented data model allows for the storage of complex and
varied data, facilitating quick querying and analysis. MongoDB's support for horizontal scaling
ensures responsiveness even with high volumes of real-time data.
MongoDB is a preferred database for IoT projects where massive amounts of sensor data
are generated. Its ability to handle diverse data types and scale horizontally makes it suitable
for storing and retrieving sensor readings, device information, and other IoT-related data.
MongoDB's flexibility accommodates the dynamic nature of IoT environments.
4. E-commerce Platforms:
MongoDB excels in log and event tracking applications where fast insertion and retrieval of
log data are crucial. Its support for indexing and efficient querying enables the analysis of
logs and events in real-time. MongoDB's horizontal scalability ensures that log and event
tracking systems can handle increasing data volumes seamlessly.
P a g e 22
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
6. Mobile App Backend Services:
7. Geospatial Applications:
MongoDB's geospatial indexing capabilities make it a suitable choice for applications that
involve location-based data, such as mapping and geolocation services. It can efficiently store
and retrieve geospatial information, supporting queries based on proximity, distance, and
other location-based criteria.
Understanding these use cases showcases MongoDB's versatility and applicability across a
wide range of scenarios, making it a robust choice for developers and organizations seeking a
flexible and scalable NoSQL database solution.
MongoDB employs a flexible, document-oriented data model where data is stored in BSON
(Binary JSON) documents. This schema-less approach allows developers to work with
dynamic and evolving data structures, accommodating changes without the need for a
predefined schema.
2. Dynamic Schema:
MongoDB's dynamic schema enables developers to add fields to documents on the fly. This
flexibility is particularly beneficial in scenarios where data structures evolve over time,
facilitating agile development and reducing the complexity associated with rigid, predefined
schemas.
3. High Performance:
MongoDB is designed for high performance, offering fast read and write operations. Its
indexing and query optimization features, combined with the ability to horizontally scale by
sharding, make it suitable for handling large volumes of data and supporting applications with
demanding performance requirements.
P a g e 23
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
4. Horizontal Scalability:
6. Aggregation Framework:
MongoDB's powerful aggregation framework allows for complex data transformations and
analysis within the database. It supports pipeline-style aggregations, enabling developers to
perform tasks such as filtering, grouping, and projecting data directly within the database.
8. Geospatial Indexing:
MongoDB includes GridFS, a specification for storing and retrieving large files such as
images, videos, and audio files. This feature allows developers to seamlessly integrate large
file storage within the database, eliminating the need for a separate file storage system.
MongoDB benefits from a vibrant and active community, providing a rich ecosystem of
tools, drivers, and extensions. This community support enhances the development
experience and ensures access to a wealth of resources for troubleshooting and optimization.
Understanding and leveraging these features make MongoDB a robust choice for modern
applications, offering developers the flexibility, scalability, and performance required to
address diverse and evolving data challenges.
P a g e 24
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
Installing MongoDB
- Disk Space: Plan for data storage, indexes, and system files.
- File System: Choose a supported file system like ext4 (Linux) or NTFS (Windows).
Installer:
P a g e 25
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
2. Select the appropriate version for your operating system (Windows, Linux, or macOS).
3. Choose the desired edition (Community) and click the download button.
4. Follow the prompts to save the installer file to your local machine.
P a g e 26
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
- Windows:
P a g e 27
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
- Follow the installation wizard, accepting the license agreement.
P a g e 28
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
- MongoDB will be installed as a Windows service.
- Linux:
- Optionally, create a symbolic link to the `bin` directory for easy access.
- macOS:
- Alternatively, download the .tgz file and follow similar steps as Linux.
- Basic Configuration:
P a g e 29
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
- Choose the installation directory.
- Network Configuration:
- Set the data directory where MongoDB will store its databases.
- Windows:
- MongoDB as a service starts automatically. Use `net start MongoDB` and `net stop
MongoDB` to manage the service.
- Use the following commands to check server status and view logs:
- `mongo admin --eval "db.runCommand({whatsmyuri: 1})"`: Check the server status and
connection URI.
Following these steps ensures a smooth MongoDB installation, configuration, and verification
process, allowing you to start working with MongoDB databases on your chosen platform.
Connecting to MongoDB
P a g e 30
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
MongoDB Connection String:
A MongoDB connection string is a URI-like string that specifies how to connect to a MongoDB
instance. It includes information such as the host, port, authentication details, and other
parameters. The general format is `mongodb://username:password@host:port/database`.
- Python (PyMongo):
import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
MongoClient client =
MongoClients.create("mongodb://username:password@host:port/database");
db.createUser({
user: "username",
pwd: "password",
roles: ["readWrite", "dbAdmin"]
});
- Authenticate in the MongoDB shell:
db.auth("username", "password");
Overview of MongoDB Compass (GUI tool for MongoDB):
P a g e 31
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
- Features:
The MongoDB Shell, mongosh, is a JavaScript and Node.js REPL environment for interacting
with MongoDB deployments in Atlas, locally, or on another remote host. Use the MongoDB
Shell to test queries and interact with the data in your MongoDB database.
To install mongosh, you can use the MongoDB Community Edition, which includes the
MongoDB server and tools, including the mongosh shell. The installation steps vary
depending on your operating system.
For Windows:
1. Download the MongoDB Community Edition installer from the official MongoDB website:
MongoDB Community Download.
3. Once installed, you can open the mongosh shell from the command prompt or PowerShell.
After installation, you can launch mongosh by typing mongosh in your terminal or command
prompt.
Remember to start the MongoDB server (mongod) before using mongosh. The installation
process may differ slightly based on updates or changes, so refer to the MongoDB
documentation for the most current information: MongoDB Installation Guides.
Helpers
Show Databases
show dbs
db // prints the current database
Switch Database
use <database_name>
Show Collections
show collections
Run JavaScript File
load("myScript.js")
- Ensure the server allows remote connections (bind to all IP addresses or specific IP).
P a g e 33
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
- Encryption:
- Authentication:
- Firewall Rules:
- Audit Logging:
- Keep MongoDB and system software up to date with the latest security patches.
By following these guidelines, you can establish a secure MongoDB deployment, ensuring
that data is protected and access is restricted to authorized users and applications.
Additional Topics
- For restoration, employ `mongorestore` to rebuild the database from the dump.
2. Multi-Cloud Availability:
- MongoDB Atlas supports multiple cloud providers, including AWS, Azure, and Google
Cloud.
- Enables flexibility in choosing the cloud infrastructure that best suits your needs.
4. Automated Scaling:
- Allows for automatic horizontal scaling by adjusting the number of nodes in a cluster based
on demand.
1. Serverless Backend:
- MongoDB Stitch is a serverless platform that eliminates the need for traditional server
management.
P a g e 35
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
- Seamlessly integrates with MongoDB Atlas for database services.
5. Real-Time Updates:
H. Resources/Equipment Required
I. Practical related Quiz
1. What is MongoDB's data model?
- A. Relational - C. Tabular
- B. Document-oriented - D. Hierarchical
P a g e 36
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
2. https://www.w3schools.com/mongodb/
3. https://www.mongodb.com/docs/manual/tutorial/install-mongodb-on-windows/
4. https://www.simplilearn.com/tutorials/mongodb-tutorial/install-mongodb-on-windows
5. https://www.geeksforgeeks.org/how-to-install-mongodb-on-windows/
K. Assessment Rubrics
Needs
Criteria Excellent (10) Good (7) Satisfactory
Improvemen Mark
(5) s
t(3)
Successfully
Installs Installs Faces
MongoDB installs MongoDB
MongoDB MongoDB with challenges
Installation with accurate and
correctly with some errors or during
Process clear steps,
clear steps. confusion. installation
showcasing deep
process.
understanding.
Demonstrates an
Understands Demonstrates Struggles to
Configuration in-depth
MongoDB basic comprehend
and Setup understanding of
configuration knowledge of MongoDB
Understanding MongoDB
and setup. MongoDB configuration.
configuration and
configuration.
setup procedures.
Effectively utilizes
MongoDB features Utilizes
Utilization of during the Attempts to Makes limited
MongoDB MongoDB use MongoDB use of
installation features MongoDB
Features process, features.
appropriately. features.
demonstrating
proficiency.
Demonstrates
excellent Demonstrates Struggles to
Troubleshooting troubleshooting Exhibits good basic troubleshoot
Skills skills, quickly troubleshootin troubleshootin issues
resolving any gskills.
gskills. effectively.
issues that may
arise.
Average Marks
P a g e 38