Name – Dhruv Bedare| Year - BE | Batch – A1 | Roll No.
– 136 | BDA
Experiment No: - 2
Aim: To install and configure MongoDB/ HBase to execute NoSQL commands
Theory:
NoSQL databases like MongoDB and HBase are designed to handle large volumes of unstructured and
semi-structured data, unlike traditional relational databases. MongoDB is a document-oriented NoSQL
database, while HBase is a column-family-based NoSQL database built on top of HDFS. These databases
are highly scalable and offer distributed storage, high performance, and flexibility in handling diverse data
models.
MongoDB :
MongoDB stands out as a leading NoSQL database, offering an open-source, document-oriented approach
that diverges from traditional relational databases. It is a distributed database that stores data as BSON
documents. BSON is a binary representation of JSON (JavaScript Object Notation). The document model
grants it the ability to store data that adheres to a user-defined format while being flexible enough to evolve
as an application’s needs change. If we have huge amount of data to be stored in tables, think of MongoDB
before RDBMS databases. MongoDB has built-in solution for partitioning and sharding our database.
MongoDB currently provides official driver support for all popular programming languages like C, C++,
Rust, C#, Java, [Link], Perl, PHP, Python, Ruby, Scala, Go and Erlang. MongoDB is widely used in
applications that need to handle large, distributed data sets, including web applications, real-time analytics,
and content management systems.
Key Features:
• Document-Oriented: Data is stored in BSON (Binary JSON) format, allowing nested fields and arrays.
• Schema Flexibility: Unlike relational databases, MongoDB allows each document to have a different
structure.
• Scalability: MongoDB can easily scale horizontally by sharding data across multiple servers.
• Indexing: Supports advanced indexing options for faster data retrieval.
• Replication: Ensures data availability and redundancy through replica sets.
Components:
1. Database: A container for collections
where data is stored, each independent
from others. Analogous to a database in
SQL systems.
2. Collection: A group of MongoDB
documents, similar to a table in relational
databases, but schema-less, allowing
flexibility.
3. Document: The basic unit of data in
MongoDB, stored in a JSON-like format
(BSON), capable of containing nested
fields and arrays.
Name – Dhruv Bedare| Year - BE | Batch – A1 | Roll No. – 136 | BDA
4. Shard: A part of MongoDB’s sharding feature that splits data across multiple servers to ensure scalability
and performance for large datasets.
5. Replica Set: A group of MongoDB servers that maintain the same data for redundancy and high
availability, where one acts as the primary node.
6. MongoDB Shell (mongo): An interactive JavaScript interface for running MongoDB queries, database
management, and other operations from the command line.
7. Index: A data structure that improves query performance by allowing fast retrieval of data, similar to an
index in a book.
8. Aggregation Framework: A set of operations that process and transform data, used for filtering,
grouping, sorting, and performing complex data analysis.
9. Storage Engine: The underlying technology that manages how data is stored on disk, with the default
being WiredTiger, providing features like compression.
10. Mongod: The primary server process in MongoDB that handles requests, manages data storage, and
executes queries.
11. Mongos: A query router used in sharded clusters that directs client requests to the appropriate shard(s)
for load balancing and data distribution.
12. MongoDB Atlas: A fully managed cloud-based database service offered by MongoDB that provides
automated database provisioning, backups, scaling, and monitoring across multiple cloud providers
(AWS, Azure, GCP).
MongoDB Installation :
Step 1 - Download the MongoDB MSI Installer Package. Download the current version of MongoDB.
Make sure you select MSI as the package you want to download.
Step 2 - Install MongoDB with the Installation Wizard
Make sure you are logged in as a user with Admin privileges. Then navigate to your downloads folder and
double click on the .msi package you just downloaded. This will launch the installation wizard.
Name – Dhruv Bedare| Year - BE | Batch – A1 | Roll No. – 136 | BDA
Click Next to start installation. Accept the license agreement then click Next.
Select the Setup Type as Complete. Select “Run service as Network Service user” and make a note of
the data directory, we’ll need this later.
We need Mongo Compass, so select it and click Next. Click Install to begin installation.
Hit Finish to complete installation.
Name – Dhruv Bedare| Year - BE | Batch – A1 | Roll No. – 136 | BDA
Step 3 – After installation, open the command prompt and Type mongosh
Hence, successfully installed MongoDB(along with Compass & Shell) in windows 11 system.
MongoDB CRUD Operations
CRUD operations in MongoDB refer to the fundamental actions performed on data: Create, Read, Update,
and Delete. CRUD operations create, read, update, and delete documents. These operations allow you to
manage and manipulate data within MongoDB collections. MongoDB’s flexibility with schema design and
powerful querying capabilities make these operations essential for effective data management.
1) Create Operations
Create or insert operations are used to add new documents to a collection. If the collection does not exist,
MongoDB will create it automatically. The primary methods are:
• [Link](document): Adds a single document to the collection. If no _id field is
provided, MongoDB generates one automatically. This method is ideal for adding individual
records.
Name – Dhruv Bedare| Year - BE | Batch – A1 | Roll No. – 136 | BDA
• [Link]([document1, document2, ...]): Adds multiple documents in one
operation. This method is efficient for bulk insertions and reduces the number of operations needed
to add multiple documents.
2) Read Operations
Read operations are used to retrieve documents from a collection based on a query. The key method for
reading documents is:
• [Link](query, projection): Retrieves documents that match the specified query. The
query parameter is used to filter documents, and the projection parameter specifies which fields to
include or exclude.
• For retrieving a single document, use [Link](query), which returns the first
document that matches the query. You can also chain methods for sorting and limiting the number
of results.
3) Update Operations
Update operations modify existing documents in a collection. The main methods are:
Name – Dhruv Bedare| Year - BE | Batch – A1 | Roll No. – 136 | BDA
• [Link](filter, update, options): Updates a single document that matches the
filter. The update parameter specifies the modifications, and the options parameter can include the
upsert option, which creates a new document if none match the filter.
• [Link](filter, update, options): Updates all documents that match the filter.
This method is useful for applying the same update to multiple documents.
• [Link](filter, replacement, options): Completely replaces a document that
matches the filter with a new document. This method is useful when you want to replace the entire
content of a document.
4) Delete Operations
Delete operations remove documents from a collection. The main methods are:
• [Link](filter): Deletes a single document that matches the filter. Only the first
matching document is removed.
• [Link](filter): Deletes all documents that match the filter. This method is useful
for bulk deletions, such as clearing a collection or removing specific records.
Inserting Data through MongoDB Compass –
Name – Dhruv Bedare| Year - BE | Batch – A1 | Roll No. – 136 | BDA
Conclusion:
This experiment demonstrates the installation, configuration, and usage of MongoDB to
execute NoSQL commands. By performing operations such as inserting, retrieving,
updating, and deleting documents, we can manage unstructured data efficiently. MongoDB’s
flexibility, scalability, and high performance make it a suitable choice for modern
applications requiring dynamic data models.