SlideShare a Scribd company logo
Quick
Overview on
MongoDB
Eman Abdel Ghaffar
Agenda
1. Introduction
2. CRUD
3. Cursors
4. Indexing
5. Schema Design principles
6. Aggregation
7. Map-Reduce
Introduction - ACID
● Relational databases usually guarantee ACID properties related to how reliably
transactions (both reads and writes) are processed.
● The NoSQL movement trades off ACID compliance for other properties, such as
100% availability, and MongoDB is the leader in the field
● https://dzone.com/articles/how-acid-mongodb
Introduction - ACID
● Atomicity requires that each transaction is executed in its entirety, or fail
without any change being applied.
● Consistency requires that the database only passes from a valid state to the
next one, without intermediate points. Any data written to the database must
be valid according to all defined rules, including constraints, cascades, triggers.
● Isolation requires that if transactions are executed concurrently, the result is
equivalent to their serial execution.
● Durability means that the the result of a committed transaction is permanent,
even if the database crashes immediately or in the event of a power loss.
Introduction - CAP
● Consistency Every read receives the most recent write or an error.
● Availability Every request receives a (non-error) response – without
guarantee that it contains the most recent write.
● Partition tolerance The system continues to operate despite an arbitrary
number of messages being dropped (or delayed) by the network between
nodes.
“It is impossible for a distributed data store to simultaneously
provide more than two out of the following three guarantees”
Introduction - MongoDB
● MongoDB is written in C++, open source and licensed under the GNU -
AGPL .
● The core database server runs via an executable called mongod (
mongodb.exe on Windows)
● The MongoDB command shell is a JavaScript-based tool for
administering the database and manipulating data.
manual/reference/mongo-shell/
CRUD - Create
● Databases and collections are created only when documents are first inserted..
● Every MongoDB document requires an _id.
db.collection.insertOne()
db.collection.insertMany()
db.collection.insert()
CRUD - Read
db.collection.find(query, projection)
db.inventory.find( {} ) SELECT * FROM inventory
db.inventory.find( { status: "D" } ) SELECT * FROM inventory WHERE status = "D"
db.inventory.find( { status: {
$in: [ "A", "D" ] } } )
SELECT * FROM inventory WHERE status in ("A", "D")
db.inventory.find( { status: "A", qty:
{ $lt: 30 } } )
SELECT * FROM inventory WHERE status = "A" AND qty < 30
db.inventory.find( {
status: "A", $or: [ { qty:
{ $lt: 30 } }, { item: /^p/ }
] } )
SELECT * FROM inventory WHERE status = "A" AND ( qty <
30 OR item LIKE "p%")
CRUD - Update
● Some Update Operators
○ $currentDate
○ $inc
○ $min
○ $max
○ $mul
○ $rename
○ $set
db.collection.update()
db.collection.findAndModify()
db.collection.updateOne()
db.collection.updateMany()
db.collection.replaceOne()
CRUD - Delete
● Indexes
○ Delete operations do not drop indexes, even if deleting all documents from
a collection.
● Atomicity
○ All write operations in MongoDB are atomic on the level of a single
document.
db.collection.remove()
db.collection.deleteOne()
db.collection.deleteMany()
Cursors
● Cursors, found in many database systems, return query result sets in batches
for efficiency iteratively.
● Queries instantiate a cursor, which is then used to retrieve a resultset in
manageable chunks, successive calls to MongoDB occur as needed to fill the
driver’s cursor buffer.
● Returning a huge result right away would mean:
○ Copying all that data into memory.
○ Transferring it over the wire.
○ Deserializing it on the client side.
Indexing
● Introduction
● Indexing Types
● Indexing Properties
Indexing- Introduction
● Index keys are typically smaller than the documents they catalog, and indexes
are typically available in RAM or located sequentially on disk.
● Covered Queries
○ When the query criteria and the projection of a query include only the indexed fields
○ Results returned directly from the index without scanning any documents or bringing
documents into memory.
● Ensure Indexes Fit in RAM
○ use the db.collection.totalIndexSize() helper, which returns index size in bytes.
Indexing - Index Types
● Single Field
● Compound Index
● Multikey Index
● Geospatial Index
● Text Indexes
● Hashed Indexes
Indexing - Index Properties
● TTL Indexes
○ The TTL index is used for TTL collections, which expire data after a period of time.
● Unique Indexes
○ A unique index causes MongoDB to reject all documents that contain a duplicate value for the
indexed field.
● Partial Indexes
○ A partial index indexes only documents that meet specified filter criteria.
● Case Insensitive Indexes
○ A case insensitive index disregards the case of the index key values.
● Sparse Indexes
○ A sparse index does not index documents that do not have the indexed field.
Schema Design
principles ● Introduction
● Embedding Vs. Referencing
● Model One-to-One
Relationships
● Model One-to-Many
Relationships
Schema Design principles - Introduction
● The application’s data access patterns should govern schema design,
with specific understanding of
○ The read/write ratio of database operations.
○ The types of queries and updates performed by the database.
○ The life-cycle of the data and growth rate of documents.
● When designing a data model, consider how applications will use your database.
○ if your application only uses recently inserted documents, consider using Capped Collections
data-modeling
Embedding Vs. Refencing
Embedding Vs. Refencing
● Embedding provides better performance for read operations, as well as the
ability to request and retrieve related data in a single database operation.
● Not all 1:1 or 1:Many relationships should be embedded in a single document.
Embedding Vs. Refencing
● References store the relationships between data by including links or
references from one document to another.
○ When embedding would not provide sufficient read performance advantages
○ Where the object is referenced from many different sources.
○ To represent complex many-to-many relationships.
○ To model large, hierarchical data sets.
One-to-One Relationships - Embedding
One-to-Many Relationships
One-to-ManyOne-to-Few
One-to-Many Relationships
One-to-Squillions
Aggregation
Aggregation
● Aggregation operations group values from multiple documents together, and
can perform a variety of operations on the grouped data to return a single
result.
● The aggregate command operates on a single collection, logically passing the
entire collection into the aggregation pipeline.
● The $match and $sort pipeline operators can take advantage of an index when
they occur at the beginning of the pipeline.
Aggregation
https://docs.mongodb.com/manual/core/aggregation-pipeline-optimization/
Aggregation - Limitations
● If any single document that exceeds the BSON Document Size limit, the
command will produce an error.
● The $group stage has a limit of 100 megabytes of RAM. By default, if the stage
exceeds this limit, $group will produce an error.
Map-Reduce
● Map-reduce is a data processing paradigm for condensing large volumes of data
into useful aggregated results.
● Map-Reduce is less efficient and more complex than the aggregation pipeline.
● All map-reduce functions in MongoDB are JavaScript and run within the
mongod process.
● Map-reduce operations take the documents of a single collection.
Questions

More Related Content

What's hot

Difference between xml and json
Difference between xml and jsonDifference between xml and json
Difference between xml and json
Umar Ali
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
Jaya Naresh Kovela
 
Using Webservice in iOS
Using Webservice  in iOS Using Webservice  in iOS
Using Webservice in iOS
Mahboob Nur
 
Connecting to a REST API in iOS
Connecting to a REST API in iOSConnecting to a REST API in iOS
Connecting to a REST API in iOS
gillygize
 
Mongo db – document oriented database
Mongo db – document oriented databaseMongo db – document oriented database
Mongo db – document oriented databaseWojciech Sznapka
 
Mongodb Introduction
Mongodb IntroductionMongodb Introduction
Mongodb Introduction
Raghvendra Parashar
 
Why JSON API?
Why JSON API?Why JSON API?
Why JSON API?
valuebound
 
MongoDB NoSQL - Developer Guide
MongoDB NoSQL - Developer GuideMongoDB NoSQL - Developer Guide
MongoDB NoSQL - Developer Guide
Shiv K Sah
 
Mongo DB
Mongo DB Mongo DB
Redis IU
Redis IURedis IU
Redis IU
Isaiah Edem
 
Data Binding in Silverlight
Data Binding in SilverlightData Binding in Silverlight
Data Binding in Silverlight
Boulos Dib
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
Amit Thakkar
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
Enoch Joshua
 
Replicating application data into materialized views
Replicating application data into materialized viewsReplicating application data into materialized views
Replicating application data into materialized views
Zach Cox
 
An Introduction to MongoDB
An Introduction to MongoDBAn Introduction to MongoDB
An Introduction to MongoDB
Chamodi Adikaram
 
Document Database
Document DatabaseDocument Database
Document Database
Heman Hosainpana
 
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
SpringPeople
 

What's hot (20)

Difference between xml and json
Difference between xml and jsonDifference between xml and json
Difference between xml and json
 
CSCi226PPT1
CSCi226PPT1CSCi226PPT1
CSCi226PPT1
 
Mongo DB Presentation
Mongo DB PresentationMongo DB Presentation
Mongo DB Presentation
 
Using Webservice in iOS
Using Webservice  in iOS Using Webservice  in iOS
Using Webservice in iOS
 
Connecting to a REST API in iOS
Connecting to a REST API in iOSConnecting to a REST API in iOS
Connecting to a REST API in iOS
 
Mongo db – document oriented database
Mongo db – document oriented databaseMongo db – document oriented database
Mongo db – document oriented database
 
Mongodb Introduction
Mongodb IntroductionMongodb Introduction
Mongodb Introduction
 
Why JSON API?
Why JSON API?Why JSON API?
Why JSON API?
 
MongoDB NoSQL - Developer Guide
MongoDB NoSQL - Developer GuideMongoDB NoSQL - Developer Guide
MongoDB NoSQL - Developer Guide
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
Redis IU
Redis IURedis IU
Redis IU
 
Indexing In MongoDB
Indexing In MongoDBIndexing In MongoDB
Indexing In MongoDB
 
MongoDB
MongoDBMongoDB
MongoDB
 
Data Binding in Silverlight
Data Binding in SilverlightData Binding in Silverlight
Data Binding in Silverlight
 
Get expertise with mongo db
Get expertise with mongo dbGet expertise with mongo db
Get expertise with mongo db
 
MongoDB for Beginners
MongoDB for BeginnersMongoDB for Beginners
MongoDB for Beginners
 
Replicating application data into materialized views
Replicating application data into materialized viewsReplicating application data into materialized views
Replicating application data into materialized views
 
An Introduction to MongoDB
An Introduction to MongoDBAn Introduction to MongoDB
An Introduction to MongoDB
 
Document Database
Document DatabaseDocument Database
Document Database
 
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
 

Similar to Quick overview on mongo db

What are the major components of MongoDB and the major tools used in it.docx
What are the major components of MongoDB and the major tools used in it.docxWhat are the major components of MongoDB and the major tools used in it.docx
What are the major components of MongoDB and the major tools used in it.docx
Technogeeks
 
Mongo db
Mongo dbMongo db
Mongo db
Gyanendra Yadav
 
Mongodb Performance
Mongodb PerformanceMongodb Performance
Mongodb Performance
Jack
 
Indexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdfIndexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdf
Malak Abu Hammad
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
ElieHannouch
 
Mongodb
MongodbMongodb
Mongodb
Thiago Veiga
 
UNIT-1 MongoDB.pptx
UNIT-1 MongoDB.pptxUNIT-1 MongoDB.pptx
UNIT-1 MongoDB.pptx
DharaDarji5
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
Knoldus Inc.
 
MOOC_PRESENTATION_FINAL_PART_1[1].pptx
MOOC_PRESENTATION_FINAL_PART_1[1].pptxMOOC_PRESENTATION_FINAL_PART_1[1].pptx
MOOC_PRESENTATION_FINAL_PART_1[1].pptx
mh3473
 
Top MongoDB interview Questions and Answers
Top MongoDB interview Questions and AnswersTop MongoDB interview Questions and Answers
Top MongoDB interview Questions and Answers
jeetendra mandal
 
MongoDB
MongoDBMongoDB
MongoDB
wiTTyMinds1
 
No sql bigdata and postgresql
No sql bigdata and postgresqlNo sql bigdata and postgresql
No sql bigdata and postgresql
Zaid Shabbir
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
Mohammed Ragab
 
Mongo presentation conf
Mongo presentation confMongo presentation conf
Mongo presentation confShridhar Joshi
 
Big Data processing with Apache Spark
Big Data processing with Apache SparkBig Data processing with Apache Spark
Big Data processing with Apache Spark
Lucian Neghina
 
Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorial
Mohan Rathour
 
Mongo db dhruba
Mongo db dhrubaMongo db dhruba
Mongo db dhruba
Dhrubaji Mandal ♛
 
MongoDB 3.2 - a giant leap. What’s new?
MongoDB 3.2 - a giant leap. What’s new?MongoDB 3.2 - a giant leap. What’s new?
MongoDB 3.2 - a giant leap. What’s new?
Binary Studio
 
Mongo indexes
Mongo indexesMongo indexes
Mongo indexes
paradokslabs
 
Query Optimization in MongoDB
Query Optimization in MongoDBQuery Optimization in MongoDB
Query Optimization in MongoDB
Hamoon Mohammadian Pour
 

Similar to Quick overview on mongo db (20)

What are the major components of MongoDB and the major tools used in it.docx
What are the major components of MongoDB and the major tools used in it.docxWhat are the major components of MongoDB and the major tools used in it.docx
What are the major components of MongoDB and the major tools used in it.docx
 
Mongo db
Mongo dbMongo db
Mongo db
 
Mongodb Performance
Mongodb PerformanceMongodb Performance
Mongodb Performance
 
Indexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdfIndexing and Query Performance in MongoDB.pdf
Indexing and Query Performance in MongoDB.pdf
 
Introduction To MongoDB
Introduction To MongoDBIntroduction To MongoDB
Introduction To MongoDB
 
Mongodb
MongodbMongodb
Mongodb
 
UNIT-1 MongoDB.pptx
UNIT-1 MongoDB.pptxUNIT-1 MongoDB.pptx
UNIT-1 MongoDB.pptx
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MOOC_PRESENTATION_FINAL_PART_1[1].pptx
MOOC_PRESENTATION_FINAL_PART_1[1].pptxMOOC_PRESENTATION_FINAL_PART_1[1].pptx
MOOC_PRESENTATION_FINAL_PART_1[1].pptx
 
Top MongoDB interview Questions and Answers
Top MongoDB interview Questions and AnswersTop MongoDB interview Questions and Answers
Top MongoDB interview Questions and Answers
 
MongoDB
MongoDBMongoDB
MongoDB
 
No sql bigdata and postgresql
No sql bigdata and postgresqlNo sql bigdata and postgresql
No sql bigdata and postgresql
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
Mongo presentation conf
Mongo presentation confMongo presentation conf
Mongo presentation conf
 
Big Data processing with Apache Spark
Big Data processing with Apache SparkBig Data processing with Apache Spark
Big Data processing with Apache Spark
 
Mongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorialMongo Bb - NoSQL tutorial
Mongo Bb - NoSQL tutorial
 
Mongo db dhruba
Mongo db dhrubaMongo db dhruba
Mongo db dhruba
 
MongoDB 3.2 - a giant leap. What’s new?
MongoDB 3.2 - a giant leap. What’s new?MongoDB 3.2 - a giant leap. What’s new?
MongoDB 3.2 - a giant leap. What’s new?
 
Mongo indexes
Mongo indexesMongo indexes
Mongo indexes
 
Query Optimization in MongoDB
Query Optimization in MongoDBQuery Optimization in MongoDB
Query Optimization in MongoDB
 

Recently uploaded

FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
Alison B. Lowndes
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
Vlad Stirbu
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
OnBoard
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
sonjaschweigert1
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Albert Hoitingh
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
Peter Spielvogel
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
ControlCase
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
Pierluigi Pugliese
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
RinaMondal9
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
UiPathCommunity
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
Product School
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Product School
 

Recently uploaded (20)

FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdfFIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
FIDO Alliance Osaka Seminar: Passkeys and the Road Ahead.pdf
 
Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........Bits & Pixels using AI for Good.........
Bits & Pixels using AI for Good.........
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Quantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIsQuantum Computing: Current Landscape and the Future Role of APIs
Quantum Computing: Current Landscape and the Future Role of APIs
 
Leading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdfLeading Change strategies and insights for effective change management pdf 1.pdf
Leading Change strategies and insights for effective change management pdf 1.pdf
 
A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...A tale of scale & speed: How the US Navy is enabling software delivery from l...
A tale of scale & speed: How the US Navy is enabling software delivery from l...
 
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
Encryption in Microsoft 365 - ExpertsLive Netherlands 2024
 
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdfSAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
SAP Sapphire 2024 - ASUG301 building better apps with SAP Fiori.pdf
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdfFIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
FIDO Alliance Osaka Seminar: Passkeys at Amazon.pdf
 
PCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase TeamPCI PIN Basics Webinar from the Controlcase Team
PCI PIN Basics Webinar from the Controlcase Team
 
By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024By Design, not by Accident - Agile Venture Bolzano 2024
By Design, not by Accident - Agile Venture Bolzano 2024
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 
Free Complete Python - A step towards Data Science
Free Complete Python - A step towards Data ScienceFree Complete Python - A step towards Data Science
Free Complete Python - A step towards Data Science
 
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
Dev Dives: Train smarter, not harder – active learning and UiPath LLMs for do...
 
How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...How world-class product teams are winning in the AI era by CEO and Founder, P...
How world-class product teams are winning in the AI era by CEO and Founder, P...
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdfFIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
FIDO Alliance Osaka Seminar: The WebAuthn API and Discoverable Credentials.pdf
 
The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
Unsubscribed: Combat Subscription Fatigue With a Membership Mentality by Head...
 

Quick overview on mongo db

  • 2. Agenda 1. Introduction 2. CRUD 3. Cursors 4. Indexing 5. Schema Design principles 6. Aggregation 7. Map-Reduce
  • 3. Introduction - ACID ● Relational databases usually guarantee ACID properties related to how reliably transactions (both reads and writes) are processed. ● The NoSQL movement trades off ACID compliance for other properties, such as 100% availability, and MongoDB is the leader in the field ● https://dzone.com/articles/how-acid-mongodb
  • 4. Introduction - ACID ● Atomicity requires that each transaction is executed in its entirety, or fail without any change being applied. ● Consistency requires that the database only passes from a valid state to the next one, without intermediate points. Any data written to the database must be valid according to all defined rules, including constraints, cascades, triggers. ● Isolation requires that if transactions are executed concurrently, the result is equivalent to their serial execution. ● Durability means that the the result of a committed transaction is permanent, even if the database crashes immediately or in the event of a power loss.
  • 5. Introduction - CAP ● Consistency Every read receives the most recent write or an error. ● Availability Every request receives a (non-error) response – without guarantee that it contains the most recent write. ● Partition tolerance The system continues to operate despite an arbitrary number of messages being dropped (or delayed) by the network between nodes. “It is impossible for a distributed data store to simultaneously provide more than two out of the following three guarantees”
  • 6. Introduction - MongoDB ● MongoDB is written in C++, open source and licensed under the GNU - AGPL . ● The core database server runs via an executable called mongod ( mongodb.exe on Windows) ● The MongoDB command shell is a JavaScript-based tool for administering the database and manipulating data. manual/reference/mongo-shell/
  • 7. CRUD - Create ● Databases and collections are created only when documents are first inserted.. ● Every MongoDB document requires an _id. db.collection.insertOne() db.collection.insertMany() db.collection.insert()
  • 8. CRUD - Read db.collection.find(query, projection) db.inventory.find( {} ) SELECT * FROM inventory db.inventory.find( { status: "D" } ) SELECT * FROM inventory WHERE status = "D" db.inventory.find( { status: { $in: [ "A", "D" ] } } ) SELECT * FROM inventory WHERE status in ("A", "D") db.inventory.find( { status: "A", qty: { $lt: 30 } } ) SELECT * FROM inventory WHERE status = "A" AND qty < 30 db.inventory.find( { status: "A", $or: [ { qty: { $lt: 30 } }, { item: /^p/ } ] } ) SELECT * FROM inventory WHERE status = "A" AND ( qty < 30 OR item LIKE "p%")
  • 9. CRUD - Update ● Some Update Operators ○ $currentDate ○ $inc ○ $min ○ $max ○ $mul ○ $rename ○ $set db.collection.update() db.collection.findAndModify() db.collection.updateOne() db.collection.updateMany() db.collection.replaceOne()
  • 10. CRUD - Delete ● Indexes ○ Delete operations do not drop indexes, even if deleting all documents from a collection. ● Atomicity ○ All write operations in MongoDB are atomic on the level of a single document. db.collection.remove() db.collection.deleteOne() db.collection.deleteMany()
  • 11. Cursors ● Cursors, found in many database systems, return query result sets in batches for efficiency iteratively. ● Queries instantiate a cursor, which is then used to retrieve a resultset in manageable chunks, successive calls to MongoDB occur as needed to fill the driver’s cursor buffer. ● Returning a huge result right away would mean: ○ Copying all that data into memory. ○ Transferring it over the wire. ○ Deserializing it on the client side.
  • 12. Indexing ● Introduction ● Indexing Types ● Indexing Properties
  • 13. Indexing- Introduction ● Index keys are typically smaller than the documents they catalog, and indexes are typically available in RAM or located sequentially on disk. ● Covered Queries ○ When the query criteria and the projection of a query include only the indexed fields ○ Results returned directly from the index without scanning any documents or bringing documents into memory. ● Ensure Indexes Fit in RAM ○ use the db.collection.totalIndexSize() helper, which returns index size in bytes.
  • 14. Indexing - Index Types ● Single Field ● Compound Index ● Multikey Index ● Geospatial Index ● Text Indexes ● Hashed Indexes
  • 15. Indexing - Index Properties ● TTL Indexes ○ The TTL index is used for TTL collections, which expire data after a period of time. ● Unique Indexes ○ A unique index causes MongoDB to reject all documents that contain a duplicate value for the indexed field. ● Partial Indexes ○ A partial index indexes only documents that meet specified filter criteria. ● Case Insensitive Indexes ○ A case insensitive index disregards the case of the index key values. ● Sparse Indexes ○ A sparse index does not index documents that do not have the indexed field.
  • 16. Schema Design principles ● Introduction ● Embedding Vs. Referencing ● Model One-to-One Relationships ● Model One-to-Many Relationships
  • 17. Schema Design principles - Introduction ● The application’s data access patterns should govern schema design, with specific understanding of ○ The read/write ratio of database operations. ○ The types of queries and updates performed by the database. ○ The life-cycle of the data and growth rate of documents. ● When designing a data model, consider how applications will use your database. ○ if your application only uses recently inserted documents, consider using Capped Collections data-modeling
  • 19. Embedding Vs. Refencing ● Embedding provides better performance for read operations, as well as the ability to request and retrieve related data in a single database operation. ● Not all 1:1 or 1:Many relationships should be embedded in a single document.
  • 20. Embedding Vs. Refencing ● References store the relationships between data by including links or references from one document to another. ○ When embedding would not provide sufficient read performance advantages ○ Where the object is referenced from many different sources. ○ To represent complex many-to-many relationships. ○ To model large, hierarchical data sets.
  • 25. Aggregation ● Aggregation operations group values from multiple documents together, and can perform a variety of operations on the grouped data to return a single result. ● The aggregate command operates on a single collection, logically passing the entire collection into the aggregation pipeline. ● The $match and $sort pipeline operators can take advantage of an index when they occur at the beginning of the pipeline.
  • 26.
  • 28. Aggregation - Limitations ● If any single document that exceeds the BSON Document Size limit, the command will produce an error. ● The $group stage has a limit of 100 megabytes of RAM. By default, if the stage exceeds this limit, $group will produce an error.
  • 29. Map-Reduce ● Map-reduce is a data processing paradigm for condensing large volumes of data into useful aggregated results. ● Map-Reduce is less efficient and more complex than the aggregation pipeline. ● All map-reduce functions in MongoDB are JavaScript and run within the mongod process. ● Map-reduce operations take the documents of a single collection.
  • 30.