SlideShare a Scribd company logo
1 of 21
Introduction to
Mongodb
Table of
content
• What is No SQL ?
• No SQL types
• What are NoSQL features ?
• ACID and CAP Theorems
• What is mongo DB ?
• Fast install mongo DB using docker container
• Create database in mongo db
• Create mongo db collections
• Mongo db CRUD operations
What is
NoSQL ?
• When people use the term “NoSQL
database”, they typically use it to refer to any
non-relational database. Some say the term
“NoSQL” stands for “non SQL” while others say
it stands for “not only SQL.” Either way, most
agree that NoSQL databases are databases
that store data in a format other than
relational tables
• The data structures used by NoSQL
databases
• Differ from those used in relational
databases
No SQL Types
Type Example
Key-value Store Redis
Wide column Store Cassandra , H.Base
Document Store Mongodb , Couchdb
Graph Store Neo4j,Infinite Graph
Key-Value
Store
Key Value Store NoSQL Database it is most
simplest NoSQL databases
Every single item in the database is stored as
an attribute key together with its value witch
key is unique . Key-value databases are highly
partitionable and allow horizontal scaling.
Key-Value Store offer Randomly access to data
by key like hash-table or dictionary data-
structures witch time complexly of reading is
o(1).
Use Case : Session store such as user
information
column Store
The column store databases are used to optimized
queries over large datasets and store columns of
data together instead of rows.
Columns store databases use a concept called a key
space. A key space is kind of like a schema in the
relational model. The key space contains all the
column families (kind of like tables in the relational
model), which contain rows, which contain
columns.
Use case : Data-intensive applications
Document
Store
A document database is a type of nonrelational
database that is designed to store and query data as
JSON-like documents. Document databases make it
easier for developers to store and query data in a
database by using the same document-model format
they use in their application code.
Document database offer flexibility to update entities
So if the data model needs to change, only the
affected documents need to be updated. No schema
update is required and no database downtime is
necessary to make the changes.
Use case :
Content management system such as blogs and video
Graph Store
• a graph database is a database designed to treat the
relationships between data as equally
• important to the data itself. It is intended to hold data
without constricting it to a pre-defined model.
• Instead, the data is stored like we first draw it out –
showing how each individual entity connects with or is
related
• to others.
• Also Graph databases are a special kind
of database storing complex data structures that would
be infeasible to store in a traditional
• relational database. They're most notably used for social
networks, as they're much more performant for certain
queries.
• Use Case : Social media connections
What are
NoSQL
features
Highly Scalable
Large data volume
NO ACID needed
Highly Flexibility
ACID and CAP
Theorems
ACID theorem :
(atomicity, consistency, isolation, durability) is a set of properties
of database transactions intended to guarantee validity even in the
event of errors)
Atomicity : A transaction is an atomic unit; hence, all the instructions
within a transaction will successfully execute, or none of them
will execute. The following transaction transfers 20 dollars from Alice’s
bank account to Bob’s bank account. If any of the instructions
fail, the entire transaction should abort and rollback.
Consistency : A database is initially in a consistent state, and it should
remain consistent after every transaction. Suppose that the
transaction in the previous example fails after Write(A_b) and the
transaction is not rolled back; then, the database will be inconsistent as
the sum of
Alice and Bob’s money, after the transaction, will not be equal to the
amount of money they had before the transaction.
Isolation : refers to the requirement that other operations cannot access
or see the data in an intermediate state during a transaction.
Durability : refers to the guarantee that once the user has been notified
of success , the transaction will persist and not be undone.
CAP Theorem
The CAP theorem (also called Brewer’s theorem after
computer scientist Eric Brewer, states that it is
impossible for a distributed data store to
simultaneously provide more than two out of the
following three guarantees) also that a distributed
database system can only guarantee two out of these
three characteristics: Consistency, Availability, and
Partition Tolerance.
Consistency
A system is said to be consistent if all nodes see the
same data at the same time.
Simply, if we perform a read operation on a
consistent system, it should return the value of the
most recent write operation. This means that, the
read should cause all nodes to return the same
data, i.e., the value of the most recent write.
Consistency
between ACID
and CAP
ACID consistency is all about
database rules. If a schema declares
that a value must be unique, then a
consistent system will enforce
uniqueness of that value across all
operations. If a foreign key implies
deleting one row will delete related
rows, then a consistent system will
ensure the state can’t contain related
rows once the base row is deleted.
CAP consistency promises that every
replica of the same logical value,
spread across nodes in a distributed
system, has the same exact value at
all times. Note that this is a logical
guarantee, rather than a physical one.
Due to the speed of light, it may take
some non-zero time to replicate
values across a cluster. The cluster
can still present a logical view by
preventing clients from viewing
different values at different nodes.
Availability
• Availability in a distributed system ensures
that the system remains operational 100% of
the time. Every request gets a (non-error)
response regardless of the individual state of a
node.
• Note: this does not guarantee that the
response contains the most recent write.
Partition Tolerance
This condition states that the system continues to run, despite the
number of messages being delayed by the network between nodes. A
system that is partition-tolerant can sustain any amount of network
failure
that doesn’t result in a failure of the entire network. Data records are
sufficiently replicated across combinations of nodes and networks to
keep the
system up through intermittent outages. When dealing with modern
distributed systems, Partition Tolerance is not an option. It’s a necessity.
Hence, we have to trade between Consistency and Availability.
What is mongo DB
?
• MongoDB is a free and open-
source cross-platform document
oriented database
• MongoDB is a document database
with the scalability and flexibility that
you want with the querying and
indexing that you need.
• Mongo uses JSON-like documents
with schemas .
• In mongo you can CREATE-UPDAT-
READ-DELETE data
MongoDB in
CAP ?
• Mongo is Constance and partition tolerated but not Highly
available
• MongoDB is a single leader based system that can have
multiple replicas. These replicas update themselves
asynchronously from Leader’s.
• Each node maintains the heartbeat of every other node to
keep track if other replicas or leader is alive or dead.
• If the leader/primary node goes down, replicas can identify
and elect a new leader based on priority, if they can form
the majority.
• Mongo db not available because If a leader disconnects
from the cluster, it takes a few seconds to elect a new
leader. So, making it unavailable for writes and reads.
Fast install mongo DB using docker container
• For fast installation mongoDB we will
use docker container but do not do this
way in the production.
• To run mongoDB inside docker use the
following command
• docker run -d -p 27017-27019:27017-
27019 --name mongodb mongo
Create
database in
mongo db
• To Create a new database in mongodb we will
use mongo CLI inside our mogodb docker
container
• 1- open bash in the docker container by using
the following command
• docker exec –it {container name or id} bash
• 2- after open mongodb container bash type
“mongo” to start connect to your mongo cluster
• 3- To create a new mongodb just type “use
{your database name}”
Mongodb
CRUD
• To create a new mongo collection use the following command
db.createCollection(collection Name)
• To insert a new document in a collection use the following command
db.{collection Name}.insert({JSON})
Example : db.users.insert({name : “mohammed ragab”,title : “Senior software
engineer”,teams : [“aptar”]});
• To read data from collection use the following command
db.{collection Name}.find();
Example : db.users.find() this command will return all documents
db.users.findOne() this command will return the first document
db.users.find({name : “mohammed ragab”}) this will return all documents that have
name equal “mohammed ragab”
• To Update document in a collection use the following command
db.users.update({‘condtion field ‘ : ‘value’ }, {new JSON}})
Example :
db.users.update({'name' : 'mohammed ragab'},{'name' : 'mohammed ragab ali’})
• To Delete a document in collection use the following command
• db.users.remove({'name' : 'mohammed ragab ali'})
Thank You !!
I hope the session was useful
Mohammed Ragab

More Related Content

What's hot

MongoDB- Crud Operation
MongoDB- Crud OperationMongoDB- Crud Operation
MongoDB- Crud Operation
Edureka!
 
Intro to NoSQL and MongoDB
Intro to NoSQL and MongoDBIntro to NoSQL and MongoDB
Intro to NoSQL and MongoDB
DATAVERSITY
 
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to ChangesBenefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Alex Nguyen
 

What's hot (20)

MongoDB- Crud Operation
MongoDB- Crud OperationMongoDB- Crud Operation
MongoDB- Crud Operation
 
MongoDB Pros and Cons
MongoDB Pros and ConsMongoDB Pros and Cons
MongoDB Pros and Cons
 
MongoDB basics & Introduction
MongoDB basics & IntroductionMongoDB basics & Introduction
MongoDB basics & Introduction
 
Top 10 frameworks of node js
Top 10 frameworks of node jsTop 10 frameworks of node js
Top 10 frameworks of node js
 
Mongo DB
Mongo DBMongo DB
Mongo DB
 
Intro to NoSQL and MongoDB
Intro to NoSQL and MongoDBIntro to NoSQL and MongoDB
Intro to NoSQL and MongoDB
 
FITC presents: Mobile & offline data synchronization in Angular JS
FITC presents: Mobile & offline data synchronization in Angular JSFITC presents: Mobile & offline data synchronization in Angular JS
FITC presents: Mobile & offline data synchronization in Angular JS
 
NOSQL vs SQL
NOSQL vs SQLNOSQL vs SQL
NOSQL vs SQL
 
No SQL and MongoDB - Hyderabad Scalability Meetup
No SQL and MongoDB - Hyderabad Scalability MeetupNo SQL and MongoDB - Hyderabad Scalability Meetup
No SQL and MongoDB - Hyderabad Scalability Meetup
 
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorialsMongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
Mongo DB: Fundamentals & Basics/ An Overview of MongoDB/ Mongo DB tutorials
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
No SQL - MongoDB
No SQL - MongoDBNo SQL - MongoDB
No SQL - MongoDB
 
Mongo db dhruba
Mongo db dhrubaMongo db dhruba
Mongo db dhruba
 
Mongo db
Mongo dbMongo db
Mongo db
 
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to ChangesBenefits of using MongoDB: Reduce Complexity & Adapt to Changes
Benefits of using MongoDB: Reduce Complexity & Adapt to Changes
 
Using NoSQL MongoDB with ColdFusion
Using NoSQL MongoDB with ColdFusionUsing NoSQL MongoDB with ColdFusion
Using NoSQL MongoDB with ColdFusion
 
ITB2016 - NoSQL with mongodb and ColdFusion (CFML)
ITB2016 - NoSQL with mongodb and ColdFusion (CFML)ITB2016 - NoSQL with mongodb and ColdFusion (CFML)
ITB2016 - NoSQL with mongodb and ColdFusion (CFML)
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
Document Database
Document DatabaseDocument Database
Document Database
 
SQL & NoSQL
SQL & NoSQLSQL & NoSQL
SQL & NoSQL
 

Similar to Introduction to mongodb

Mongo presentation conf
Mongo presentation confMongo presentation conf
Mongo presentation conf
Shridhar Joshi
 
MongoDB Lab Manual (1).pdf used in data science
MongoDB Lab Manual (1).pdf used in data scienceMongoDB Lab Manual (1).pdf used in data science
MongoDB Lab Manual (1).pdf used in data science
bitragowthamkumar1
 
NoSQL and CouchDB: the view from MOO
NoSQL and CouchDB: the view from MOONoSQL and CouchDB: the view from MOO
NoSQL and CouchDB: the view from MOO
James Hollingworth
 

Similar to Introduction to mongodb (20)

Mongo db
Mongo dbMongo db
Mongo db
 
Mongo presentation conf
Mongo presentation confMongo presentation conf
Mongo presentation conf
 
When NOT to use MongoDB
When NOT to use MongoDBWhen NOT to use MongoDB
When NOT to use MongoDB
 
Relational and non relational database 7
Relational and non relational database 7Relational and non relational database 7
Relational and non relational database 7
 
NoSql Databases
NoSql DatabasesNoSql Databases
NoSql Databases
 
NoSQL and MongoDB
NoSQL and MongoDBNoSQL and MongoDB
NoSQL and MongoDB
 
MongoDB Lab Manual (1).pdf used in data science
MongoDB Lab Manual (1).pdf used in data scienceMongoDB Lab Manual (1).pdf used in data science
MongoDB Lab Manual (1).pdf used in data science
 
Modern databases and its challenges (SQL ,NoSQL, NewSQL)
Modern databases and its challenges (SQL ,NoSQL, NewSQL)Modern databases and its challenges (SQL ,NoSQL, NewSQL)
Modern databases and its challenges (SQL ,NoSQL, NewSQL)
 
NOSQL
NOSQLNOSQL
NOSQL
 
Datastores
DatastoresDatastores
Datastores
 
NoSQL.pptx
NoSQL.pptxNoSQL.pptx
NoSQL.pptx
 
Why no sql ? Why Couchbase ?
Why no sql ? Why Couchbase ?Why no sql ? Why Couchbase ?
Why no sql ? Why Couchbase ?
 
NoSQL and CouchDB: the view from MOO
NoSQL and CouchDB: the view from MOONoSQL and CouchDB: the view from MOO
NoSQL and CouchDB: the view from MOO
 
Datastores
DatastoresDatastores
Datastores
 
Mongo db transcript
Mongo db transcriptMongo db transcript
Mongo db transcript
 
Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorial
 
Introduction to NoSQL
Introduction to NoSQLIntroduction to NoSQL
Introduction to NoSQL
 
NOSQL and MongoDB Database
NOSQL and MongoDB DatabaseNOSQL and MongoDB Database
NOSQL and MongoDB Database
 
Database Technologies
Database TechnologiesDatabase Technologies
Database Technologies
 
مقدمة عن NoSQL بالعربي
مقدمة عن NoSQL بالعربيمقدمة عن NoSQL بالعربي
مقدمة عن NoSQL بالعربي
 

Recently uploaded

"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
mphochane1998
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
Neometrix_Engineering_Pvt_Ltd
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
9953056974 Low Rate Call Girls In Saket, Delhi NCR
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
AldoGarca30
 

Recently uploaded (20)

Generative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPTGenerative AI or GenAI technology based PPT
Generative AI or GenAI technology based PPT
 
PE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and propertiesPE 459 LECTURE 2- natural gas basic concepts and properties
PE 459 LECTURE 2- natural gas basic concepts and properties
 
A Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna MunicipalityA Study of Urban Area Plan for Pabna Municipality
A Study of Urban Area Plan for Pabna Municipality
 
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments""Lesotho Leaps Forward: A Chronicle of Transformative Developments"
"Lesotho Leaps Forward: A Chronicle of Transformative Developments"
 
Integrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - NeometrixIntegrated Test Rig For HTFE-25 - Neometrix
Integrated Test Rig For HTFE-25 - Neometrix
 
Double Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torqueDouble Revolving field theory-how the rotor develops torque
Double Revolving field theory-how the rotor develops torque
 
Online food ordering system project report.pdf
Online food ordering system project report.pdfOnline food ordering system project report.pdf
Online food ordering system project report.pdf
 
data_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdfdata_management_and _data_science_cheat_sheet.pdf
data_management_and _data_science_cheat_sheet.pdf
 
Thermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.pptThermal Engineering -unit - III & IV.ppt
Thermal Engineering -unit - III & IV.ppt
 
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced LoadsFEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
FEA Based Level 3 Assessment of Deformed Tanks with Fluid Induced Loads
 
Online electricity billing project report..pdf
Online electricity billing project report..pdfOnline electricity billing project report..pdf
Online electricity billing project report..pdf
 
Hostel management system project report..pdf
Hostel management system project report..pdfHostel management system project report..pdf
Hostel management system project report..pdf
 
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
Unit 4_Part 1 CSE2001 Exception Handling and Function Template and Class Temp...
 
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLEGEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
GEAR TRAIN- BASIC CONCEPTS AND WORKING PRINCIPLE
 
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
Call Girls in South Ex (delhi) call me [🔝9953056974🔝] escort service 24X7
 
Block diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.pptBlock diagram reduction techniques in control systems.ppt
Block diagram reduction techniques in control systems.ppt
 
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptxOrlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
Orlando’s Arnold Palmer Hospital Layout Strategy-1.pptx
 
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
1_Introduction + EAM Vocabulary + how to navigate in EAM.pdf
 
Work-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptxWork-Permit-Receiver-in-Saudi-Aramco.pptx
Work-Permit-Receiver-in-Saudi-Aramco.pptx
 
School management system project Report.pdf
School management system project Report.pdfSchool management system project Report.pdf
School management system project Report.pdf
 

Introduction to mongodb

  • 2. Table of content • What is No SQL ? • No SQL types • What are NoSQL features ? • ACID and CAP Theorems • What is mongo DB ? • Fast install mongo DB using docker container • Create database in mongo db • Create mongo db collections • Mongo db CRUD operations
  • 3. What is NoSQL ? • When people use the term “NoSQL database”, they typically use it to refer to any non-relational database. Some say the term “NoSQL” stands for “non SQL” while others say it stands for “not only SQL.” Either way, most agree that NoSQL databases are databases that store data in a format other than relational tables • The data structures used by NoSQL databases • Differ from those used in relational databases
  • 4. No SQL Types Type Example Key-value Store Redis Wide column Store Cassandra , H.Base Document Store Mongodb , Couchdb Graph Store Neo4j,Infinite Graph
  • 5. Key-Value Store Key Value Store NoSQL Database it is most simplest NoSQL databases Every single item in the database is stored as an attribute key together with its value witch key is unique . Key-value databases are highly partitionable and allow horizontal scaling. Key-Value Store offer Randomly access to data by key like hash-table or dictionary data- structures witch time complexly of reading is o(1). Use Case : Session store such as user information
  • 6. column Store The column store databases are used to optimized queries over large datasets and store columns of data together instead of rows. Columns store databases use a concept called a key space. A key space is kind of like a schema in the relational model. The key space contains all the column families (kind of like tables in the relational model), which contain rows, which contain columns. Use case : Data-intensive applications
  • 7. Document Store A document database is a type of nonrelational database that is designed to store and query data as JSON-like documents. Document databases make it easier for developers to store and query data in a database by using the same document-model format they use in their application code. Document database offer flexibility to update entities So if the data model needs to change, only the affected documents need to be updated. No schema update is required and no database downtime is necessary to make the changes. Use case : Content management system such as blogs and video
  • 8. Graph Store • a graph database is a database designed to treat the relationships between data as equally • important to the data itself. It is intended to hold data without constricting it to a pre-defined model. • Instead, the data is stored like we first draw it out – showing how each individual entity connects with or is related • to others. • Also Graph databases are a special kind of database storing complex data structures that would be infeasible to store in a traditional • relational database. They're most notably used for social networks, as they're much more performant for certain queries. • Use Case : Social media connections
  • 9. What are NoSQL features Highly Scalable Large data volume NO ACID needed Highly Flexibility
  • 10. ACID and CAP Theorems ACID theorem : (atomicity, consistency, isolation, durability) is a set of properties of database transactions intended to guarantee validity even in the event of errors) Atomicity : A transaction is an atomic unit; hence, all the instructions within a transaction will successfully execute, or none of them will execute. The following transaction transfers 20 dollars from Alice’s bank account to Bob’s bank account. If any of the instructions fail, the entire transaction should abort and rollback. Consistency : A database is initially in a consistent state, and it should remain consistent after every transaction. Suppose that the transaction in the previous example fails after Write(A_b) and the transaction is not rolled back; then, the database will be inconsistent as the sum of Alice and Bob’s money, after the transaction, will not be equal to the amount of money they had before the transaction. Isolation : refers to the requirement that other operations cannot access or see the data in an intermediate state during a transaction. Durability : refers to the guarantee that once the user has been notified of success , the transaction will persist and not be undone.
  • 11. CAP Theorem The CAP theorem (also called Brewer’s theorem after computer scientist Eric Brewer, states that it is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees) also that a distributed database system can only guarantee two out of these three characteristics: Consistency, Availability, and Partition Tolerance.
  • 12. Consistency A system is said to be consistent if all nodes see the same data at the same time. Simply, if we perform a read operation on a consistent system, it should return the value of the most recent write operation. This means that, the read should cause all nodes to return the same data, i.e., the value of the most recent write.
  • 13. Consistency between ACID and CAP ACID consistency is all about database rules. If a schema declares that a value must be unique, then a consistent system will enforce uniqueness of that value across all operations. If a foreign key implies deleting one row will delete related rows, then a consistent system will ensure the state can’t contain related rows once the base row is deleted. CAP consistency promises that every replica of the same logical value, spread across nodes in a distributed system, has the same exact value at all times. Note that this is a logical guarantee, rather than a physical one. Due to the speed of light, it may take some non-zero time to replicate values across a cluster. The cluster can still present a logical view by preventing clients from viewing different values at different nodes.
  • 14. Availability • Availability in a distributed system ensures that the system remains operational 100% of the time. Every request gets a (non-error) response regardless of the individual state of a node. • Note: this does not guarantee that the response contains the most recent write.
  • 15. Partition Tolerance This condition states that the system continues to run, despite the number of messages being delayed by the network between nodes. A system that is partition-tolerant can sustain any amount of network failure that doesn’t result in a failure of the entire network. Data records are sufficiently replicated across combinations of nodes and networks to keep the system up through intermittent outages. When dealing with modern distributed systems, Partition Tolerance is not an option. It’s a necessity. Hence, we have to trade between Consistency and Availability.
  • 16. What is mongo DB ? • MongoDB is a free and open- source cross-platform document oriented database • MongoDB is a document database with the scalability and flexibility that you want with the querying and indexing that you need. • Mongo uses JSON-like documents with schemas . • In mongo you can CREATE-UPDAT- READ-DELETE data
  • 17. MongoDB in CAP ? • Mongo is Constance and partition tolerated but not Highly available • MongoDB is a single leader based system that can have multiple replicas. These replicas update themselves asynchronously from Leader’s. • Each node maintains the heartbeat of every other node to keep track if other replicas or leader is alive or dead. • If the leader/primary node goes down, replicas can identify and elect a new leader based on priority, if they can form the majority. • Mongo db not available because If a leader disconnects from the cluster, it takes a few seconds to elect a new leader. So, making it unavailable for writes and reads.
  • 18. Fast install mongo DB using docker container • For fast installation mongoDB we will use docker container but do not do this way in the production. • To run mongoDB inside docker use the following command • docker run -d -p 27017-27019:27017- 27019 --name mongodb mongo
  • 19. Create database in mongo db • To Create a new database in mongodb we will use mongo CLI inside our mogodb docker container • 1- open bash in the docker container by using the following command • docker exec –it {container name or id} bash • 2- after open mongodb container bash type “mongo” to start connect to your mongo cluster • 3- To create a new mongodb just type “use {your database name}”
  • 20. Mongodb CRUD • To create a new mongo collection use the following command db.createCollection(collection Name) • To insert a new document in a collection use the following command db.{collection Name}.insert({JSON}) Example : db.users.insert({name : “mohammed ragab”,title : “Senior software engineer”,teams : [“aptar”]}); • To read data from collection use the following command db.{collection Name}.find(); Example : db.users.find() this command will return all documents db.users.findOne() this command will return the first document db.users.find({name : “mohammed ragab”}) this will return all documents that have name equal “mohammed ragab” • To Update document in a collection use the following command db.users.update({‘condtion field ‘ : ‘value’ }, {new JSON}}) Example : db.users.update({'name' : 'mohammed ragab'},{'name' : 'mohammed ragab ali’}) • To Delete a document in collection use the following command • db.users.remove({'name' : 'mohammed ragab ali'})
  • 21. Thank You !! I hope the session was useful Mohammed Ragab