0% found this document useful (0 votes)
10 views53 pages

Se DBMS 2023 Unit4

This document provides an overview of NoSQL databases, detailing their characteristics, types, and specific implementations such as MongoDB. It explains concepts like BASE and CAP, compares NoSQL with relational databases, and outlines CRUD operations along with various data types supported by MongoDB. Additionally, it discusses MongoDB's advantages, storage engines, and the flexibility of document-oriented data management.

Uploaded by

nkvr6xdmch
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)
10 views53 pages

Se DBMS 2023 Unit4

This document provides an overview of NoSQL databases, detailing their characteristics, types, and specific implementations such as MongoDB. It explains concepts like BASE and CAP, compares NoSQL with relational databases, and outlines CRUD operations along with various data types supported by MongoDB. Additionally, it discusses MongoDB's advantages, storage engines, and the flexibility of document-oriented data management.

Uploaded by

nkvr6xdmch
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/ 53

Getting started with

NoSQL Databases
UNIT 4
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL

What Is BASE?

● Basically Available: The system is guaranteed to be available in event of failure.


● Soft State: The state of the data could change without application interactions due to
eventual consistency.
● Eventual Consistency: The system will be eventually consistent after the
application input. The data will be replicated to different nodes and will eventually
reach a consistent state. But the consistency is not guaranteed at a transaction level.
Getting started with NoSQL

What Is CAP?
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL
Types of NoSQL
Databases
UNIT 4
Types of NoSQL

Here are the four main types of NoSQL databases:


● Key-value stores
● Document databases
● Column-oriented databases
● Graph databases
key-value pair database

● The simplest type of NoSQL database is a key-value pair database.


● Every data element in the database is stored as a key value pair consisting of an
attribute name (or "key") and a value.
● It is like a relational database with only two columns: the key or attribute name
(such as "state") and the value (such as "Alaska").
● They cannot be used if the requirement is to query by data, have relationships
between the data or if we need to operate on multiple keys at the same time
● Used to store: session info, user profiles
key-value pair database

● What are keys?


● Keys are unique identifiers.
● It uniquely identifies value from a set of value
● Given a key the value can be very easily fetched.
● The key has to be unique
● Keys are stored in the namespace, which is a collection of identifiers
● A database can have one or multiple namespace
key-value pair database

● What are values?


● Values are data stored along with keys
● It can be a number,string,array, image
● Typically the key value database do not impose any checks on the data types of
values.
key-value pair database
key-value pair database

● Difference between key value pair and relational database?

Key value pair Relational

They have simple, non trivial data models They have strict adherence to relational
data model

Does not require a schema Mandatory to define schema

They can store huge amount of data spread They can store less data that supports table
across multiple server fitting within a single server

There is no table so no not null, check There is not null, check constraint, joins
constraint, joins hence best to store hence not suitable for unrelated data
unrelated data

No support for SQL Supports SQL


Document database

● A document database stores data in JSON, or XML documents.


● In a document database, documents can be nested.
● A document database does not need a schema to be defined prior to placing
the data in the document.
● When a document is added to a database, it creates the underlying data
structures needed to support the document.
● Each document can have different set of attributes.
● The only way to lookup a value is using key
● It provides a flexibility to lookup a document based on attribute values.
● Eg: db.customer.find({location:”canada”});
Document database
Document database

● Difference between Document and relational database?

Document Relational

They do not have a fixed schema They require a fixed predefined schema

Have its own set of key value pairs Each record has the same set of columns
Document database
Document database
Column Family database

● Terminologies:
● Row oriented storage: Data is organized into rows
● column oriented storage: Data is organized into columns
● column families: Columns that are frequently accessed together
● Rows can be homogeneous (having same set of columns) or
heterogeneous (having different set of columns)
Column Family database
Graph Database

● A graph database is a type of NoSQL database that is designed to handle data


with complex relationships and interconnections.
● In a graph database, data is stored as nodes and edges, where nodes represent
entities and edges represent the relationships between those entities.
● One of the main advantages of graph databases is their ability to handle and
represent relationships between entities
Graph Database
Graph Database
MongoDB
UNIT 4
About MongoDB

● MongoDB is a document database.


● It stores data in a type of JSON format called BSON
● MongoDB is an open source NoSQL database management program.
● NoSQL (Not only SQL) is used as an alternative to traditional relational databases.
● NoSQL databases are quite useful for working with large sets of distributed data.
● MongoDB is a tool that can manage document-oriented information, store or retrieve
information.
● MongoDB is used for high-volume data storage, helping organizations store large
amounts of data while still performing rapidly.
● the MongoDB architecture is made up of collections and documents.
● Documents are made up of key-value pairs
Advantages of MongoDB

● Schema-less. MongoDB doesn't require predefined schemas. It stores any type of data.
This gives users the flexibility to create any number of fields in a document, making it
easier to scale MongoDB databases compared to relational databases.
● Document-oriented. One of the advantages of using documents is that these objects
map to native data types in several programming languages., Having embedded
documents also reduces the need for database joins, which can lower costs.
● Scalability. A core function of MongoDB is its horizontal scalability, which makes it a
useful database for companies running big data applications.
● Replication of data-MongoDB can run over multiple servers. The data is duplicated to
keep the system up and also keep its running condition in case of hardware failure.
● Provides high performance.
● Load balancing. MongoDB handles load balancing without the need for a separate,
dedicated load balancer, through either vertical or horizontal scaling.
Storage engines of MongoDB

● The storage engine is the component of the database that is responsible for
managing how data is stored, both in memory and on disk.

● MongoDB supports multiple storage engines, as different engines perform better for
specific workloads

● It determines the efficiency, scalability, and performance of database operations.

● MongoDB provides pluggable storage engine architecture, allowing users to select


the most suitable storage engine for their specific workload requirements

● Following are the storage engines:


Storage engines of MongoDB

WiredTiger Storage Engine (Default)


● WiredTiger is the default and most widely used storage engine in MongoDB since version 3.2
● It is known for its performance, scalability, and concurrency control mechanisms.
● It is well-suited for most workloads and is recommended for new deployments.
● WiredTiger provides a document-level concurrency model, checkpointing, and compression, among
other features.
● In MongoDB Enterprise, WiredTiger also supports Encryption at Rest.

In-Memory Storage Engine


● In-Memory Storage Engine is available in MongoDB Enterprise.
● Rather than storing documents on-disk, it retains them in-memory for more predictable data latencies.
● However, as data is stored in memory, it's important to ensure that the server has sufficient RAM to
accommodate the entire dataset.
Storage engines of MongoDB

Encrypted Storage Engine


● MongoDB Enterprise Edition offers the capability to encrypt data.
● Encryption for WiredTiger is provided for Enterprise version 3.2 and above.
● This features allows the MongoDb to encrypt and decrypt the data whenever needed.
● It ensures it complies with the security and privacy policies of industry or organization

MMAPv1 (deprecated since MongoDB 4.0):


● MMAPv1 was the original storage engine used in MongoDB. It relied on memory-mapped files for
data storage and retrieval.
● While simple and easy to use, MMAPv1 had limitations in terms of concurrency and performance,
especially for workloads with high write throughput.
● MongoDB deprecated MMAPv1 in favor of WiredTiger due to WiredTiger's superior performance and
feature set.
Storage engines of MongoDB
CRUD operations in MongoDB

Create Operation
● Create or insert operations add new documents to a collection.
● If the collection does not currently exist, insert operations will create the collection.
● MongoDB provides the following methods to insert documents into a collection:

○ db.collection.insertOne() New in version 3.2

○ db.collection.insertMany() New in version 3.2

● In MongoDB, insert operations target a single collection.


● All write operations in MongoDB are atomic on the level of a single document.
CRUD operations in MongoDB

Read Operation
● Read operations retrieve documents from a collection; i.e. query a collection for documents.
● MongoDB provides the following methods to insert documents into a collection:

○ db.collection.find()

● You can specify query filters or criteria that identify the documents to return.
.
CRUD operations in MongoDB

Update Operation
● Update operations modify existing documents in a collection.
● MongoDB provides the following methods to update documents of a collection:
○ db.collection.updateOne() New in version 3.2

○ db.collection.updateMany() New in version 3.2

○ db.collection.replaceOne() New in version 3.2

● In MongoDB, update operations target a single collection.


● All write operations in MongoDB are atomic on the level of a single document.
● You can specify criteria, or filters, that identify the documents to update.
● These filters use the same syntax as read operations.
.
CRUD operations in MongoDB

Delete Operation
● Delete operations remove documents from a collection.
● MongoDB provides the following methods to update documents of a collection:
○ db.collection.deleteOne() New in version 3.2

○ db.collection.deleteMany() New in version 3.2

● In MongoDB, delete operations target a single collection.


● All write operations in MongoDB are atomic on the level of a single document.
● You can specify criteria, or filters, that identify the documents to remove.
● These filters use the same syntax as read operations.
Data Types in MongoDB

1. String

● One of the most basic and widely used data types is the string.

● To represent text, the string type is utilized.

Example:

{
"intern_name": "Edward Bill",
"intern_skills": "Software Development",
"intern_salary": 7500,
"intern_status": true,
}
Data Types in MongoDB

2. Integer

● Numeric values are stored using the integer data type.


● Depending on the server, it can store 32-bit or 64-bit numbers.

Example:

{
"intern_name": "Edward Bill",
"intern_skills": "Software Development",
"intern_salary": 7500,
"intern_status": true,
}
Data Types in MongoDB

3. Double
● Numeric numbers containing 8 bytes floating-point are stored using the double data type.
● An example of a document with a double value in the field intern score is shown below.

Example:

{
"intern_name": "Edward Bill",
"intern_skills": "Software Development",
"intern_score": 87.75,
"intern_status": true,
}
Data Types in MongoDB

4. Boolean
● Boolean (true or false) values are stored with the boolean data type.
● Booleans take up less space than integers or strings and avoid unwanted comparison side effects

Example:.

{
"intern_name": "Edward Bill",
"intern_skills": " Software Development",
"intern_score": 87.75,
"intern_status": true,
}
Data Types in MongoDB

5. Array
● The array is stored using the array data type.
● We can store several values in a single key of the document with an array data type.

Example:

{
" intern_name": "Edward Bill",
" intern_skills": ["Software Development", "C++", "Java"],
" intern_score": 87.75,
" intern_status": true,
}
Data Types in MongoDB

7. Date
● The current date or time is stored in the ‘Date’ data type.
● The returning date can be done in a variety of ways; either a string or a date object.
● There are three strategies that can be used in this situation.
○ The Date() function returns a string.
○ Return a date object with New Date().
○ ISODate() returns a date object as well.

Example:

{
"employee_name": "John Doe",
"employee_dob": ISODate("2004-04-10T12:45:42.389Z"),
"employee_marks": 80.40
}
Data Types in MongoDB

8. Timestamp
● The term "Timestamp" refers to a set of characters used to describe the date and time of an
occurrence.
● The timestamp data type is commonly used to track the creation, editing, and updating of
documents.
● Such characters are stored in the timestamp data type.
● To construct a timestamp, use the new Timestamp().

Example:

{
"product_code": "0000-XYZ",
"product_price": 39.99,
"product_created": Timestamp(1531456567, 1),
"product_availability": true,
}
Data Types in MongoDB

9. Null
● The NULL data type is used to represent a value of zero or no value, as the name implies.
● When a null value field in a document is queried, this is what it looks like:

Example:

{
"product_code": "0000-XYZ",
"product_price": 39.99,
"product_color": null,
"product_availability": true,
}

You might also like