0% found this document useful (0 votes)
26 views38 pages

No SQL PR 1 & 2

The Laboratory Manual for the Introduction to NoSQL course provides a comprehensive framework for Diploma in Computer Engineering students, focusing on practical skills and competencies in NoSQL databases such as MongoDB, Cassandra, Neo4j, and Redis. It emphasizes hands-on experience, aligning with the Competency-Focused Outcome-Based Curriculum, and includes guidelines for safety, assessment criteria, and practical outcomes. The manual also explores the CAP theorem and various types of NoSQL databases, preparing students for real-world applications and decision-making in database management.

Uploaded by

dkchauhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views38 pages

No SQL PR 1 & 2

The Laboratory Manual for the Introduction to NoSQL course provides a comprehensive framework for Diploma in Computer Engineering students, focusing on practical skills and competencies in NoSQL databases such as MongoDB, Cassandra, Neo4j, and Redis. It emphasizes hands-on experience, aligning with the Competency-Focused Outcome-Based Curriculum, and includes guidelines for safety, assessment criteria, and practical outcomes. The manual also explores the CAP theorem and various types of NoSQL databases, preparing students for real-world applications and decision-making in database management.

Uploaded by

dkchauhan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 38

Diploma Engineering

Laboratory Manual

Introduction to NoSQL (4360704)

Semester-6 of Diploma in Computer


Engineering

Enrolment No
Name
Branch
Academic Term
Institute

A Y Dadabhai technical Institute,


Kosamba 601
Introduction to NoSQL
(4360704)

Laboratory Manual
Institute’s Vision:

Institute’s Mission:

Department’s Vision:

Department’s Mission:
Certificate

This is to certify that Mr./Ms. …..…………………………………………………………. Enrolment No.


………….………..………………. of Semester …………. of Diploma in Computer Engineering of
Institute …………………………………….……………………………………………………………..….. (GTU
code: …………..) has satisfactorily completed the term work in course Introduction to
NoSQL (4360704) for the academic year: ………...…………….… Term: Odd/Even as
prescribed in the GTU curriculum.

Place: …………………….….

Date: …………………………

Subject Faculty Head of the Department


Preface

The fundamental objective of any practical, laboratory, or field work is to foster


essential skills and cultivate creative abilities among students, enabling them to tackle
real- time challenges by developing pertinent competencies in the psychomotor domain.
Aligned with this vision, GTU has meticulously crafted the Competency-Focused
Outcome-Based Curriculum - 2021 (COGC-2021) for Diploma engineering programs.
This curriculum places greater emphasis on practical work compared to theoretical
studies, underscoring the significance of skill enhancement. It recognizes the value of
utilizing every moment allocated to practical work for students, instructors, and
lecturers to achieve meaningful outcomes through hands-on experiences rather than
mere theoretical discourse. This approach is crucial for the effective implementation of
the competency-focused outcome-based Green curriculum-2021.

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:

1. Basic and Discipline specific knowledge: Apply knowledge of basic mathematics,


science and engineering fundamentals and engineering specialization to solve the
engineering problems.
2. Problem analysis: Identify and analyse well-defined engineering problems using codified
standard methods.
3. Design/development of solutions: Design solutions for engineering well-defined
technical problems and assist with the design of systems components or processes to
meet specified needs.
4. Engineering Tools, Experimentation and Testing: Apply modern engineering tools and
appropriate technique to conduct standard tests and measurements.
5. Engineering practices for society, sustainability and environment: Apply appropriate
technology in context of society, sustainability, environment and ethical practices.
6. Project Management: Use engineering management principles individually, as a team
member or a leader to manage projects and effectively communicate about well-defined
engineering activities.
7. Life-long learning: Ability to analyse individual needs and engage in updating in the
context of technological changes in field of engineering.
Practical Outcome - Course Outcome matrix
Course Outcomes (COs):
CO1. Analyze the impact of the CAP theorem on various NoSQL databases, highlighting the
trade-offs between consistency, availability, and partition tolerance in database
systems.
CO2. Apply MongoDB's features and basic CRUD operations to design and manipulate data
structures effectively, demonstrating proficiency in utilizing a document- oriented
database.
CO3. Demonstrate Cassandra's data model and query language (CQL), showcasing the
ability to create and manage distributed data tables efficiently.
CO4. Identify the significance of graph databases, illustrating their practical applications in
solving complex relationship-oriented problems.
CO5. Utilize Redis data structures and functionalities to implement efficient caching
strategies, showcasing the role of Redis in enhancing data retrieval performance.
Sr.
No. Experiment/Practical Outcome CO1 CO2 CO3 CO4 CO5

1. Introduction and Types of NoSQL Databases √ - - - -

2. Introduction and Installation of MongoDB - √ - - -

3. Basic CRUD Operations with MongoDB - √ - - -

4. Introduction and Setup of Cassandra - - √ - -

5. Data Modeling and Simple Queries with - - √ - -


Cassandra

6. Introduction to Neo4j Graph Databases - - - √ -

7. Basic Graph Queries and Implementations with - - - √ -


Neo4j

8. Redis Basics: Introduction and Key-Value - - - - √


Operations
Progressive Assessment Sheet

Marks
Sr. No Experiment/Practical Outcome Page Date Sign
(10)

1. Introduction and Types of NoSQL Databases

2. Introduction and Installation of MongoDB

3. Basic CRUD Operations with MongoDB

4. Introduction and Setup of Cassandra

5. Data Modeling and Simple Queries


withCassandra

6. Introduction to Neo4j Graph Databases

7. Basic Graph Queries and Implementations with


Neo4j

8. Redis Basics: Introduction and Key-Value


Operations
Name: Raidan Ujef Enrolment: 226010307098 Batch: CO3

Practical 1. Introduction and Types of NoSQL Databases

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.

B. Relevant Program Outcomes (POs)


1. Application of Fundamental Knowledge:

- Apply foundational knowledge in computer science and information technology to


comprehend the principles and types of NoSQL databases.

2. Problem Analysis in Database Context:

- Identify and analyze specific engineering challenges related to NoSQL databases using
established methodologies and principles.

3. Designing Solutions for NoSQL Issues:

- Develop solutions for well-defined technical problems in the context of NoSQL databases,
contributing to the design of effective data management systems.

4. Utilization of Engineering Tools for Database Testing:

- Apply modern engineering tools and testing techniques to assess and validate the
performance of NoSQL databases, ensuring adherence to standard practices.

5. Engineering Practices in NoSQL Context:

- Integrate appropriate NoSQL technologies considering societal impact, sustainability,


environmental aspects, and ethical considerations in database design and management.

6. Project Management in NoSQL Implementation:

- Utilize engineering management principles to coordinate and communicate effectively


within a team while managing projects related to NoSQL database development.

7. Commitment to Continuous Learning in NoSQL Technology:

- 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 a strong foundation in NoSQL databases, covering principles, architecture, and


essential characteristics.

2. CAP Theorem Insight:

- Understand the implications of the CAP theorem on distributed systems, emphasizingthe


trade-offs between consistency, availability, and partition tolerance.

3. NoSQL Types Proficiency:

- Differentiate between document-oriented, key-value, column-family, and graphdatabases,


discerning their specific applications.

4. Decision-Making and Application:

- Apply theoretical knowledge to practical scenarios, making informed decisions onNoSQL


database selection based on project requirements.

D. Relevant Course Outcomes (Cos)


Analyze the impact of the CAP theorem on various NoSQL databases, highlighting the trade-
offs between consistency, availability, and partition tolerance in database systems.

E. Practical Outcome (PRo)


- Attain a thorough grasp of NoSQL databases, covering principles, CAP theoreminsights,
and diverse database features.

- Develop skills to make informed choices by exploring real-world use cases, understanding
factors influencing database selection, and conducting comparativeanalyses.

- Apply theoretical knowledge practically, ensuring students can implement NoSQL


concepts and make effective decisions in various project scenarios.

F. Expected Affective domain Outcome (ADos)


1. Enhanced Interest and Engagement:

- Foster increased interest and engagement among students, promoting a positiveattitude


towards the study of NoSQL databases.

2. Improved Decision-Making Confidence:

- Strengthen students' confidence in making well-informed decisions regarding database


choices through practical insights and hands-on experience.

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:

1. Multiple Data Model Compatibility:

- 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.

2. Enhanced Scalability and Availability:

- NoSQL offers simplified scalability with a serverless, peer-to-peer architecture, allowing


for horizontal scaling and improved performance.

- Sharding enables efficient handling of massive data volumes, and auto-replication


ensures high availability in case of failures.

3. Global Data Distribution:

- Advanced NoSQL databases facilitate global data distribution by operating across multiple
cloud regions and data centers.

- Contrastingly, relational databases often rely on centralized applications, while NoSQL


minimizes wait times by distributing data globally.

4. Minimal Downtime:

- NoSQL databases feature robustness and minimal downtime.

- Serverless architecture and data replication across nodes ensure business continuity, with
alternative nodes providing access in case of a malfunction.

Can NoSQL completely replace relational databases?


No, NoSQL cannot entirely replace relational databases. The choice between the two depends
on the specific needs of an organization. NoSQL is preferred for handling diverse data types
P a g e 12
Introduction to NoSQL (4360704)
Name: Raidan Ujef Enrolment: 226010307098 Batch: CO3

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.

Types of NoSQL Databases


There are four main types of NoSQL databases, each catering to specific use cases:

1. Document-oriented Databases:

- Store data in flexible, JSON-like documents.

- Examples: MongoDB, CouchDB.

2. Key-Value Stores:

- Simplest NoSQL model, storing data as key-value pairs.

- Examples: Redis, DynamoDB.

3. Column-family Stores:

- Organize data into columns rather than rows.

- Examples: Apache Cassandra, HBase.

4. Graph Databases:

- Designed for managing and querying interconnected data.

- Examples: Neo4j, Amazon Neptune.

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.

3. Partition Tolerance (P):


- The system continues to operate despite
network partitions that may cause
communication failures betweennodes.

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:

- CA (Consistency and Availability): Prioritizing availability over consistency, responding with


possibly stale data. Examples include Cassandra, CouchDB, Riak, and Voldemort.

- AP (Availability and Partition Tolerance): Emphasizing availability over consistency, possibly


responding with stale data. Distributed across nodes, designed to operate reliably despite
network partitions. Examples include Amazon DynamoDB and Google Cloud Spanner.

- CP (Consistency and Partition Tolerance): Focusing on consistency over availability,


responding with the latest updated data. Distributed across nodes, designed to operate
reliably in the face of network partitions. Examples include Apache HBase, MongoDB, and
Redis.

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.

Comparisons between MongoDB, Cassandra, Neo4j, and Redis


Criteria MongoDB Cassandra Neo4j Redis
Data Model Document- Column-family Graph Key-valuestore
oriented (BSON)
Query Language MongoDB Query CQL Cypher Query N/A
Language (MQL) (Cassandra Language (Command-
Query based)
Language)
Schema Dynamicschema Dynamicschema Schema-based Schemaless
(flexible)
Scalability Horizontal Horizontal Horizontal Horizontal
scaling through scaling scaling scaling
sharding
Consistency Tunable Tunable Strong Eventual
consistency consistency consistency consistency
(Eventual to (Eventual to
Strong) Strong)
Partition Yes Yes Yes Yes
Tolerance
Use Case Focus General- purpose, Wide-column Graph-based, Cache, real-
document store, time- relationships time analytics
storage series data

P a g e 14
Introduction to NoSQL (4360704)
Name: Raidan Ujef Enrolment: 226010307098 Batch: CO3

Indexing Multiple types, Secondary Indexing based Limited


including indexes on relationships indexingoptions
compound and
geo-spatial
indexes
Query Good Excellent Excellent for Very fast (in-
Performance graph queries memory
storage)
ACID Supports ACID Limited support Supports ACID Supports
Transactions transactions for transactions transactions transactions
through multi
commands
Community Large and active Active Active Active
Support community community community community
Use Cases Content Time-series Social networks, Caching,
management data, logging, frauddetection messagebroker
systems, e- IoT
commerce, real-
time analytics

Factors Influencing Choice of Database


- Data Model: Choose based on whether document-oriented, key-value, column-family, or
graph data models are most suitable for the application.

-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.

- Development and Operational Considerations: Evaluate factors like ease of development,


community support, and operational overhead when choosing a NoSQL database for a
project.

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:

- Provide comprehensive documentation, tutorials, and learning materials to guide students


through the practical exercises.

I. Practical related Quiz


Multiple Choice Questions:

1. What does the term "NoSQL" stand for?

a) Non-Operational SQL c) New Operational SQL

b) Not Only SQL d) None of the above

2. What is the primary advantage of NoSQL databases over traditional relationaldatabases?

a) Strict schema enforcement c) Flexibility in handlingunstructured


data
b) Limited scalability
d) Exclusive use of SQLlanguage

3. In the CAP theorem, what does "P" stand for?


c) Persistence
a) Performance
d) Provisioning
b) Partition Tolerance

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

6. Which NoSQL database emphasizes availability and partition tolerance overconsistency?

a) MongoDB c) Neo4j

b) Cassandra d) Redis

P a g e 16
Introduction to NoSQL (4360704)
Name: Raidan Ujef Enrolment: 226010307098 Batch: CO3

b) To highlight trade-offs inachieving


7. What is the purpose of the CAP
theorem in the context of distributed consistency,
NoSQL databases?
a) To prioritize performance
over consistency

8. Which factor is crucial in deciding the appropriate NoSQL database for an application?

a) Number of tables in the c) Specific use caserequirements


database
d) Operating systemcompatibility
b) Size of the development
team

Match each NoSQL database type to its corresponding description.

A. Document-oriented i. Stores data in flexible, JSON-like documents.


B. Key-Value Stores ii. Simplest NoSQL model, storing data as key-value pairs.
C. Column-familyStores iii. Organizes data into columns rather than rows.
D. Graph Databases iv. Designed for managing and querying interconnected data.

Introduction to NoSQL (4360704) Page 17


Name: Raidan Ujef Enrolment: 226010307098 Batch: CO3

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

Signature with date

Introduction to NoSQL (4360704) Page 18


Introduction to NoSQL (4360704)
Practical 2. Introduction and Installation of MongoDB

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.

B. Relevant Program Outcomes (POs)


1. Basic and Discipline-Specific Knowledge:

- Apply fundamental engineering knowledge to understand MongoDB's role and


significance in modern database systems.

2. Problem Analysis:

- Identify and analyze engineering challenges related to MongoDB installation and


connectivity using established methods.

3. Design/Development of Solutions:

- Design solutions for well-defined technical problems encountered during the installation
and connection processes in MongoDB.

4. Engineering Tools, Experimentation, and Testing:

- Utilize appropriate engineering tools to conduct experiments and tests during the
MongoDB installation, ensuring proficiency in modern database technologies.

5. Engineering Practices for Society, Sustainability, and Environment:

- Apply MongoDB installation practices considering societal, sustainability,


andenvironmental aspects, adhering to ethical considerations.

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.

C. Competency and Practical Skills


1. Technical Proficiency:

- Demonstrate competence in installing MongoDB, understanding its features, and


navigating its environment.

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.

3. Documentation and Communication:

- Effectively document the installation process and communicate findings, demonstrating


clarity and precision in conveying technical information.

4. Adaptability:

- Exhibit adaptability by quickly grasping MongoDB's installation procedures and staying


abreast of any updates or changes in the installation process.

D. Relevant Course Outcomes (Cos)


Apply MongoDB's features and basic CRUD operations to design and manipulate data
structures effectively, demonstrating proficiency in utilizing a document-oriented database.

E. Practical Outcome (PRo)


Proficiently install MongoDB, configure, and establish successful connectivity to designated
instance

F. Expected Affective domain Outcome (ADos)


Develop a positive attitude towards MongoDB installation, fostering confidence and
competence.

G. Prerequisite Theory

Overview of MongoDB

MongoDB is a widely-used, open-source NoSQL database that embraces a document-


oriented data model. Unlike traditional relational databases, MongoDB stores data in flexible,
JSON-like documents, allowing for dynamic schemas and easy scalability. It offers high
performance, horizontal scalability, and is particularly well-suited for applications with
rapidlyevolving schemas and large amounts of unstructured or semi-structured data.

NoSQL databases vs. relational databases

Relational Database NoSQL


It is used to handle data coming in high
It is used to handle data coming in low velocity. velocity.
It gives only read scalability. It gives both read and write scalability.
It manages structured data. It manages all type of data.

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 (Binary JSON) data format

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:

BSON employs binary encoding to represent JSON-like documents in a compact and


efficient manner. This binary format facilitates faster data processing and reduces storage
space compared to traditional text-based JSON.

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.

4. Extended Data Types:

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.

5. Support for Querying and Indexing:


P a g e 21
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)

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.

Use cases and scenarios where MongoDB excels

1. Content Management Systems (CMS):

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.

3. Internet of Things (IoT) Applications:

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 is well-suited for e-commerce applications handling a vast range of product


information, customer data, and transaction histories. Its ability to model complex
relationships between products and categories, coupled with horizontal scaling capabilities,
ensures high performance and scalability for e-commerce platforms, especially during peak
times.

5. Log and Event Tracking:

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:

MongoDB serves as an effective backend database for mobile applications, providing a


JSON-like data model that aligns well with the data structures commonly used in mobile
development. Its automatic sharding and replication features ensure high availability and
reliability for 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.

8. Dynamic and Agile Development Environments:

MongoDB is particularly advantageous in development environments that prioritize


flexibility and adaptability. Its schema-less design allows developers to iterate quickly,
accommodating changes to application requirements without the need for extensive schema
modifications.

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 Features and Advantages

1. Document-Oriented Data Model:

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:

MongoDB excels in scalable architectures through horizontal scaling. By distributing data


across multiple servers via sharding, MongoDB can handle increased data loads and provide
seamless scalability without sacrificing performance.

5. Indexing and Query Optimization:

MongoDB supports various indexing techniques, enhancing query performance.


Developers can create indexes on fields to speed up data retrieval, and the query optimizer
optimizes execution plans for efficient searches, ensuring optimal performance even with
extensive datasets.

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.

7. Replication for High Availability:

MongoDB provides built-in replication features to ensure high availability. By maintaining


multiple copies of data across replica sets, MongoDB can continue to operate even in the
event of a server failure. Automatic failover mechanisms further enhance the system's
reliability.

8. Geospatial Indexing:

MongoDB includes geospatial indexing, making it well-suited for location-based


applications. This feature enables efficient storage and retrieval of geospatial data,
supporting queries based on proximity, distance, and other location-specific criteria.

9. GridFS for Large File Storage:

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.

10. Community and Ecosystem:

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

System Requirements and Compatibility:

MongoDB is a cross-platform NoSQL database, compatible with various operating systems.


Before installation, ensure your system meets the following requirements:

- Operating Systems: Windows, Linux, macOS

- Processor Architecture: 64-bit recommended

- Memory (RAM): Allocate sufficient RAM for optimal performance.

- Disk Space: Plan for data storage, indexes, and system files.

- File System: Choose a supported file system like ext4 (Linux) or NTFS (Windows).

- Network: Ensure robust and low-latency network connectivity.Downloading the MongoDB

Installer:

1. Visit the official MongoDB website


(https://www.mongodb.com/try/download/community)to access the download page.

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)

Installation on Windows, Linux, and macOS:

- Windows:

- Run the downloaded installer (.msi file).

P a g e 27
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
- Follow the installation wizard, accepting the license agreement.

- Choose the "Complete" setup type for a standard installation.

P a g e 28
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
- MongoDB will be installed as a Windows service.

- Linux:

- Extract the downloaded archive (.tgz file).

- Move the extracted files to a desired location.

- Optionally, create a symbolic link to the `bin` directory for easy access.

- MongoDB is now ready for configuration.

- macOS:

- Install MongoDB using Homebrew: `brew tap mongodb/brew && brew


installmongodb/brew/mongodb-community`.

- Alternatively, download the .tgz file and follow similar steps as Linux.

- MongoDB is installed and ready for configuration.

Configuration Options During Installation:

- Basic Configuration:

P a g e 29
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
- Choose the installation directory.

- Configure whether MongoDB should run as a service (Windows).

- Network Configuration:

- Specify the port for MongoDB to listen on (default: 27017).

- Configure network binding options for access control.

- Data and Log Paths:

- Set the data directory where MongoDB will store its databases.

- Configure the log path for MongoDB server logs.

Verifying the Installation:

- Open a command prompt or terminal window.

- Run the MongoDB shell: `mongod`.

- Verify the MongoDB server version and connection.

Starting and Stopping the MongoDB Server:

- Windows:

- MongoDB as a service starts automatically. Use `net start MongoDB` and `net stop
MongoDB` to manage the service.

- Linux and macOS:

- Start MongoDB: `mongod` or `sudo service mongod start`.

- Stop MongoDB: `mongod --shutdown` or `sudo service mongod stop`.

Checking Server Status and Logs:

- Use the following commands to check server status and view logs:

- `mongod --version`: Display MongoDB version.

- `mongod --fork --logpath /var/log/mongodb/mongod.log`: Start MongoDB as a background


process with logging.

- `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`.

Connecting via MongoDB Shell:

1. Open a terminal or command prompt.

2. Run the `mongo` command.

3. Connect to a MongoDB instance using the connection string:


`mongo"mongodb://username:password@host:port/database"`

Connecting through a MongoDB Driver (e.g., Python, JavaScript, Java):Using a MongoDB

driver in your preferred programming language:

- Python (PyMongo):

from pymongo import MongoClient


client = MongoClient("mongodb://username:password@host:port/database")
- JavaScript (Node.js):

const MongoClient = require('mongodb').MongoClient;


const client = new MongoClient("mongodb://username:password@host:port/database", {
useNewUrlParser: true });
- Java:

import com.mongodb.client.MongoClient;
import com.mongodb.client.MongoClients;
MongoClient client =
MongoClients.create("mongodb://username:password@host:port/database");

Authentication and User Management:

- Create a new user:

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)

MongoDB Compass is a graphical user interface (GUI) tool for MongoDB:

- Features:

- Visual exploration of data.

- Index management and query optimization.

- Real-time server statistics.

- Schema analysis and visualization.

- Query performance profiling.

MongoDB Shell (mongosh)

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.

2. Run the installer and follow the installation instructions.


P a g e 32
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)

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")

Connecting to a Remote MongoDB Instance:

When connecting to a MongoDB instance on a remote server:

- Modify the connection string with the remote server's details.

- 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)

Securing the MongoDB Deployment:

- Encryption:

- Use SSL/TLS for encrypted communication between clients and servers.

- Authentication:

- Require authentication for all connections.

- Create user accounts with minimal necessary privileges.

- Firewall Rules:

- Restrict incoming connections to trusted IP addresses.

- Utilize network security groups to control access.

- Role-Based Access Control (RBAC):

- Assign roles to users based on their responsibilities.

- Regularly review and update user roles.

- Audit Logging:

- Enable MongoDB's audit log to track user activities.

- Monitor and analyze the audit log for security insights.

- Updates and Patching:

- Keep MongoDB and system software up to date with the latest security patches.

- Regularly check for MongoDB updates and apply them promptly.

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

Backup and Restore Strategies:

1. mongodump and mongorestore:

- Use `mongodump` to create a binary export of the database.

- For restoration, employ `mongorestore` to rebuild the database from the dump.

2. File System Snapshots:

- Take snapshots of the underlying file system for point-in-time recovery.

- Ensure MongoDB is in a consistent state during snapshot creation.


P a g e 34
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)

3. Continuous Baup Services:

- Leverage third-party backup services or MongoDB Atlas Backup to automate regular


backups.

- Enable incremental backups for efficient storage usage.

4. Backup to Remote Location:

- Store backups in a remote location to protect against data center failures.

- Consider encryption for data in transit and at rest

Introduction to MongoDB Atlas (MongoDB's Cloud Database Service):

1. Managed Cloud Database:

- MongoDB Atlas is a fully-managed cloud database service provided by MongoDB, Inc.

- It handles administrative tasks like backups, upgrades, and scaling automatically.

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.

3. Security and Compliance:

- Provides built-in security features such as encryption at rest and in transit.

- Complies with industry standards and certifications.

4. Automated Scaling:

- Allows for automatic horizontal scaling by adjusting the number of nodes in a cluster based
on demand.

- Ensures performance optimization without manual intervention.

Introduction to MongoDB Stitch (Backend as a Service):

1. Serverless Backend:

- MongoDB Stitch is a serverless platform that eliminates the need for traditional server
management.

- Developers focus on writing application logic without managing infrastructure.

2. Integration with Atlas:

P a g e 35
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
- Seamlessly integrates with MongoDB Atlas for database services.

- Provides a unified platform for backend development and database management.

3. Authentication and Authorization:

- Handles user authentication and authorization with ease.

- Supports various authentication providers, including email/password, Google, and


Facebook.

4. HTTP Services and Triggers:

- Allows the creation of HTTP services for serverless functions.

- Supports triggers for automatic execution of functions based on events.

5. Real-Time Updates:

- Enables real-time data synchronization using MongoDB's change streams.

- Applications receive instant updates when data changes in the database.

By adhering to these strategies, practices, and leveraging MongoDB's cloud services,


developers can ensure the robustness, scalability, and efficiency of MongoDB deployments,
whether in traditional environments or cloud-based solutions.

H. Resources/Equipment Required
I. Practical related Quiz
1. What is MongoDB's data model?

- A. Relational - C. Tabular

- B. Document-oriented - D. Hierarchical

2. In MongoDB, what does BSON stand for?

- A. Binary Object Structured - C. Binary JSON


Notation
- D. Binary JSON Object
- B. Binary Oriented JSON Notation

3. Which of the following is a feature of BSON in MongoDB?

- A. Supports fewer data types - C. Binary encoding for


than JSON compact storage

- B. Text-based format - D. Limited support for


complex data structures

P a g e 36
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)

4. What use case is MongoDB particularly well-suited for?


- A. Handling only structured - B. Content Management
data Systems (CMS)
- C - Applications with staticschemas D. Single-location data
sources

5. Which of the following is a key feature of MongoDB Compass?


- A. Query performanceprofiling - C. Binary JSON

- B. Binary encoding - D. Horizontal scalability

6. What is the primary purpose of MongoDB Stitch?

- A. Backup and restore


- C. Geospatial applications
- B. Backend as a Service(BaaS)
- D. Real-time analytics
7. How can you connect to a MongoDB instance via the mongosh shell?
- A. Using the `mongo` - C. Via a MongoDB
command connection string

- B. By creating a symbolic link - D. Through HTTP services


8. What is a primary consideration for securing a MongoDB deployment?
- A. Using a non-supported filesystem - C. Keeping MongoDB andsystem
software up to date
- B. Creating a single point offailure
- D. Avoiding authentication forall
connections

9. Which of the following is a characteristic of MongoDB Atlas?


- A. Server management - C. Manual scaling
required
- D. Multi-cloud support
- B. Single-cloud availability
10. What MongoDB feature allows for automatic horizontal scaling by adjusting thenumber of nodes
in a cluster based on demand?

- A. Indexing and query - C. Replication for high


optimization availability

- B. MongoDB Stitch - D. Automated scaling in


MongoDB Atlas

11. What command is used to show the available databases in mongosh?


A. list dbs C. view dbs

B. show databases D. display databases


P a g e 37
Introduction to NoSQL (4360704)
Introduction to NoSQL (4360704)
J. References Links
1. https://www.geeksforgeeks.org/what-is-mongodb-working-and-features/

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

Signature with date

P a g e 38

You might also like