0% found this document useful (0 votes)
25 views12 pages

NoSql Unit 3

Unit 3 covers NoSQL databases, specifically focusing on MongoDB's Key-Value and Document database structures. It discusses features, use cases, consistency models, transactions, availability, scaling, and various query features, highlighting MongoDB's flexibility and efficiency for applications like e-commerce, content management, and real-time analytics. The document also emphasizes the advantages of MongoDB's schema flexibility and its ability to handle large volumes of data across different application types.
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)
25 views12 pages

NoSql Unit 3

Unit 3 covers NoSQL databases, specifically focusing on MongoDB's Key-Value and Document database structures. It discusses features, use cases, consistency models, transactions, availability, scaling, and various query features, highlighting MongoDB's flexibility and efficiency for applications like e-commerce, content management, and real-time analytics. The document also emphasizes the advantages of MongoDB's schema flexibility and its ability to handle large volumes of data across different application types.
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

UNIT-3

NoSQL Key–Value Database using MongoDB:


NoSQL Database:
NoSQL (Not Only SQL) is a non-relational database designed to handle
large amount of structured data, semi-structured data, and unstructured
data.

[Link]–Value Database:
A Key–Value database stores data as a collection of key and value pairs,
where each key uniquely identifies its corresponding value.

Key–Value in MongoDB:
MongoDB is mainly a document database; it also supports Key–Value
structure because each document contains key and value as a pair.

Ex:
{
"id": 101,
"name": "NoSql",
"branch": "CSE"
}
Features of Key–Value Database:
• It has Simple structure and highly scalable.
• it has fast read and write mode.

Use Cases:
• It uses online Shopping cart.
• User profiles and real-time data

2. Document Database:
A database that stores data in the form of JSON-like documents instead of
rows and columns.
Document Database using MongoDB:
A Document database stores data in the form of documents.
Format like JSON (BSON internally), Documents stored in collections and
collections stored in database.
Ex:
{
"student_id": 101,
"name": "NoSql",
"year": 3rd year,
}
Features of Document Database:
• Improves search performance by using indexing.
• It has horizontal scaling.

Use Cases:
• In E-Commerce Applications Stores product details, categories, prices.
• In Social Media Applications Stores posts, comments, likes data.

Consistency:
• Consistency ensuring that the database always remains in a valid and
correct state after any operation.
• operation that are insert, update, delete.

Consistency Model in MongoDB:


•The system is always available for read/write operations.

•The data may change over time even without new input because of
replication.
•All copies of data will become consistent after some time.
•MongoDB can provide strong consistency using read/write mode.
Replica Sets and Consistency:
• MongoDB uses Replica Sets.
• One server act’s as Primary and Other servers act as Secondary.
• Writes/Read mode goes to Primary server.
• Data is replicated to Secondary servers.
• This ensures High availability and Data consistency.

Transactions in MongoDB:
A transaction is a group of database operations executed as a single unit.
MongoDB Transactions Support multi-document ACID transactions.
Atomicity – All operations succeed or none are applied.
Consistency – Database remains in a valid state.
Isolation – Transactions do not interfere with each other.
Durability – Once committed, data is permanently stored
Transactions are Used in Banking systems, E-commerce payments, Order
management systems and Financial applications.

Availability in MongoDB:
Availability refers to the ability of the database system to remain accessible
and operational at all times, even in case of failures.

How MongoDB Provides Availability:


MongoDB ensures high availability using Replica Sets.
• A group of MongoDB servers that maintain the same data.
• One server acts as Primary.
• Other servers act as Secondary.

Working
* All write operations go to the Primary server.
* Data is automatically replicated to Secondary servers.
* If the Primary server fails.
* One Secondary is automatically selected as the new Primary.
Features of Availability
• In this Feature of availability the data does not loss.
• In this Feature of availability the Automatic recovery.

QUERY FEATURES:
Query features refer to the methods used to retrieve, filter, and manipulate data
from the database.

[Link] Query (find):


• Basic Query is also nothing but find.
• The find () method is used to retrieve documents from a collection.

Example: [Link]()

IN JAVASCRIPT RETURN ALL DOCUMENTS

[Link] Data:
It is used to retrieve specific documents based on conditions.

Example: [Link]({ branch: "CSE" })

[Link] Operators:
Used for conditional queries:
• $gt → Greater than
• $lt → Less than
• $gte → Greater than or equal
• $lte → Less than or equal

Example: [Link]({ marks: { $gt: 80 } })

4. Sorting:

It is used to arrange data.

Example: [Link]().sort({ marks: 1 })


1 is for Ascending
-1 is for Descending
5. Projection:

Used to display selected fields only.

Example: [Link]({}, { name: 1, branch: 1 })

[Link]:

Used for data analysis like grouping and counting.

Example: [Link]([
{ $group: { _id: "$branch", total: { $sum: 1 } } }
])

7. Indexing
• It Improves query performance
• Speeds up the data retrieval

Scaling in MongoDB:

Scaling is the process of increasing the capacity of a database system to handle


more data and users.

Types of Scaling
In this scaling there are two types. they are in given below.

[Link] Scaling (Scaling Up):


•Increasing the resources of a single server (CPU, RAM, Storage)
• It is Simple to implement
• It Has hardware limitations
Example: Upgrading RAM from 8GB to 32GB

2. Horizontal Scaling (Scaling Out)


• Adding multiple servers to distribute data
• MongoDB supports this using Sharding

Advantages of Scaling
• Handles large volumes of data
• Improves performance
• Supports high traffic applications

Suitable Use Cases of MongoDB:


Suitable use cases refer to the types of applications where MongoDB is most
effective and efficient.
Use Cases:
[Link] Management Systems (CMS)
• It Stores articles, blogs, images, videos
• It is a Flexible schema for different content types
2. E-Commerce Applications
• It has a Shopping carts
• And also Order management
3. Real-Time Analytics
• It monitoring the Website traffic.
• User activity tracking and Live dashboards
4. Web Applications
• It has Backend database for dynamic websites
• And Handle’s large user data
5. Mobile Applications
• It Stores user data and app content
• And Sync’s the data in real time
6. Internet of Things (IoT)
• It Stores sensor data
• And also it Handles continuous data flow
7. Social Media Applications
• It Stores posts, comments, likes
• It Managing the rapidly changing data
[Link] Data Applications
• It Handles large and distributed datasets
• And also Supports horizontal scaling

Content Management System (CMS):


A Content Management System (CMS) is a software application used to create,
store, manage, and modify digital content such as text, images, videos, and web
pages.
CMS using MongoDB
MongoDB is widely used in CMS because it provides:
• It provides Flexible data storage
• And Easy handling of different content types
• It has a High scalability
Content like blogs, articles, comments, and media files are stored as documents.
Example:
{
"title": "NoSQL Database",
"Facutly": "Keerthana",
"content": "Introduction to MongoDB",
"date": "2026-03-19"
}
Features
1. It has high Flexible schema
2. It is Easy content updates
3. It has High performance
4. It has Scalable storage
5. It Supports multimedia content
Applications
• Blogging websites
• News portals
• Educational platforms
• Media publishing systems

Event Logging:
Event logging is the process of recording events or activities that occur in a
system or application.
In event logging, every action (event) such as user activity, system changes, or
errors is stored as a record in the database.
MongoDB is well-suited for event logging because it can handle large volumes
of continuously generated data.
Example:
{
"user": "Keerthana",
"action": "login",
"time": "10:30 AM"
}
Applications:
It has System monitoring and Error tracking
It has User activity tracking
It has Security auditing
Features:
It handles large amounts of data
It Supports real-time data insertion
It has Flexible schema (different event types)
It has High performance

Blogging Platforms:
Blogging platforms are software or websites that allow users to create, publish,
and manage blog content easily without advanced coding knowledge.

• It Provide tools to write articles such as posts.


• It has Allowing to add images, videos, and links
• It Manage comments and users
• And also help to publish the content in the online

Examples:
• Personal blogs
• Educational blogs
• Technical blogs
Features:

It is Easy to create content


User-friendly interface and Customized design
Supports multimedia content
Comment and interaction supports

Web Analytics and Real-Time Analytics:


[Link] Analytics:

Web analytics is the process of collecting, analyzing, and reporting data about
website usage.
Data Stored:
The data stored in the Page views, Number of visitors, User sessions, Clicks and
navigation

Uses
• Understand user behavior
• Improve website performance
• Track traffic sources

[Link]-Time Analytics:
Real-time analytics is the process of analyzing data immediately as it is
generated.

Data Stored
The data stored in the Live user activity, Transactions, Sensor/IoT data
and Social media updates

Uses
• Live dashboards
• Instant decision making
• Monitoring systems

E-Commerce Applications:
An E-commerce application is a system that allows users to buy and sell
products or services online.

E-commerce applications store and manage:

• Product details
• Customer information
• Orders and transactions
• Shopping cart data

MongoDB is suitable because it handles large and dynamic data efficiently.

Example Document

{
"product_id": 101,
"name": "Laptop",
"price": 50000,
"category": "Electronics"
}

Features
It has a Flexible schema (different product types) and High scalability
It has Fast data retrieval
And also Handles large traffic

Applications
• Online shopping websites
• Order management systems
• Payment processing systems

Complex Transactions Spanning Different Operations:


A complex transaction is a transaction that involves multiple operations across
different documents or collections, executed as a single unit.
In MongoDB, complex transactions may include:

• Insert operations
• Update operations
• Delete operations

All these operations are executed together.


If any one operation fails, the entire transaction is rolled back.

Example:
In an e-commerce application:

1. Deduct amount from user account, 2. update product stock and 3. Create
order record

If any step fails, all changes are cancelled.

Features

It Supports multi-document transactions


In this feature ensures ACID properties
It Maintains data consistency
It Provides reliability

Applications
• Banking systems
• E-commerce applications
• Financial transactions
• Order processing systems

Queries Against Varying Aggregate Structure in


MongoDB

Queries against varying aggregate structure refer to the ability to query


documents that have different structures or fields within the same collection.

In MongoDB, documents in a collection do not need to have the same schema.


They are

• Some documents may have certain fields


• Others may not have those fields
Still, MongoDB allows querying all of them.

Example:

{ "name": "A", "marks": 80 }


{ "name": "B", "grade": "A" }

Here:

• First document has marks


• Second document has grade

Both are stored in the same collection.

Query Example:
[Link]({ marks: { $gt: 70 } })

This retrieves only documents that contain marks field.

Features

It has flexible schema


It can handles semi-structured data
In this no need for fixed structure and easy data retrieval

Advantages
• Stores different types of data together
• Reduces complexity
• Supports dynamic applications

Completed unit 3

You might also like