Se DBMS 2023 Unit4
Se DBMS 2023 Unit4
NoSQL Databases
UNIT 4
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL
Getting started with NoSQL
What Is BASE?
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
They have simple, non trivial data models They have strict adherence to relational
data model
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
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
● 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
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:
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
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
1. String
● One of the most basic and widely used data types is the string.
Example:
{
"intern_name": "Edward Bill",
"intern_skills": "Software Development",
"intern_salary": 7500,
"intern_status": true,
}
Data Types in MongoDB
2. Integer
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,
}