Module 3
Module 3
-
Prof. Kaushika S.,
Department of CSE,
SOET, CMR University.
Document DB
Document databases are a type of NoSQL database that store and retrieve data in the form
of flexible, JSON, XML or BSON documents.
These databases are designed to handle diverse and evolving data structures without
requiring a fixed schema.
So in the document data model, each document has a key-value pair below is an example
for the same.
Popular Key-Value DB
MongoDB
Couchbase Server
CouchDB
Cosmos DB
Arango DB
Amazon DocumentDB.
JSON and XML documents
RDBMS vs Document DB
Document DB Working
This is a data model which works as a semi-structured data model in which the
records and data associated with them are stored in a single document which
means this data model is not completely unstructured.
The main thing is that data here is stored in a document.
Example
Each product, like a t-shirt or a book, is stored as a separate "document." These documents
contain all the details about the product, like its name, price, and description
If the store wants to add new information, like color options for a t-shirt, MongoDB let
them do it without changing everything else.
Features
Query
Scaling
Features
Document Data Features
Example: In an online banking application, when a user transfers money from one account to
another, MongoDB ensures data consistency by using ACID transactions. This guarantees that
the transaction deducts the correct amount from the sender's account and adds it to the
recipient's account reliably, preventing any data discrepancies or errors.
Document Data Features
Transactions: These databases support transactions, ensuring that multiple operations are
executed as a single, atomic unit to maintain data integrity.
Example: In an e-commerce platform, when a customer places an order for multiple items,
MongoDB supports transactions to ensure that all operations, such as updating inventory
levels, deducting payment from the customer, and confirming the order, are executed as a
single atomic unit. This maintains data integrity and prevents any partial updates or
inconsistencies in the order processing.
Document Data Features
Query Features: They offer rich querying capabilities, allowing users to perform complex
queries, including filtering, sorting, and aggregation.
Scaling: Document databases can scale horizontally by distributing data across multiple
servers, enabling them to handle large volumes of data and high traffic loads.
Event Logging
MongoDB is like a digital journal where computers record important events that happen.
These events could be anything from a user signing into a website to a sensor detecting a
change in temperature.
MongoDB is good at keeping track of all these events because it can handle lots of them
and makes it easy to find and understand what happened when.
Use Cases
Imagine MongoDB as a digital filing cabinet for websites. Content Management Systems
(CMS) use MongoDB to store all the articles, pictures, and videos you see online.
MongoDB is great for this because it's like a magic filing cabinet that can store all kinds of
things in neat folders and find them quickly when needed.
Use Cases
Web Analytics
MongoDB is like a superpowered calculator for websites. Web Analytics tools use
MongoDB to keep track of how many people visit a website, which pages they look at, and
how long they stay.
MongoDB helps them do this because it can handle lots of calculations and make sense of
all the data to help website owners understand their visitors better.
Use Cases
Ecommerce Applications:
Ecommerce applications use MongoDB to keep track of all the products they sell, who's
buying them, and when they get delivered.
MongoDB is perfect for this because it can handle lots of shoppers and products, making it
easy for online stores to grow and manage their business smoothly.
When not to use
Complex Transactions:
Document databases might not be the best choice for applications needing to do many complicated tasks
all at once, like moving money between bank accounts.
Document databases may not be great for organizing information that's closely connected, like how all the
pieces of a puzzle fit together.
Document databases may not be the top pick for searching and finding specific pieces of information
quickly if the data is very organized and structured, like finding a word in a big dictionary.
Document databases may not be the best for collecting and studying huge amounts of organized
information for making smart business decisions, like looking at sales data to see which products are
popular.
SQL vs MongoDB Queries
SQL queries in relational databases and MongoDB queries in document databases differ in
syntax and structure.
Example: