SlideShare uma empresa Scribd logo
1 de 58
Engineer
Bryan Reinero
@blimpyacht
Relational to MongoDB
Unhelpful Terms
• NoSQL
• Big Data
• Distributed
What’s the data model?
MongoDB
• Non-relational
• Scalable
• Highly available
• Full featured
• Document database
RDBMS MongoDB
Table, View ➜ Collection
Row ➜ Document
Index ➜ Index
Join ➜ Embedded Document
Foreign Key ➜ Reference
Partition ➜ Shard
Terminology
Sample Document
{
maker : "M.V. Agusta",
type : sportbike,
rake : 7,
trail : 3.93,
engine : {
type : "internal cumbustion",
layout : "inline"
cylinders : 4,
displacement : 750,
},
transmission : {
type : "cassette",
speeds : 6,
pattern : "sequential”,
ratios : [ 2.7, 1.94, 1.34, 1, 0.83, 0.64 ]
}
}
Relational DBs
• Attribute columns are valid for every row
• Duplicate rows are not allowed
• Every column has the same type and
same meaning
As a document store, MongoDB supports a
flexible schema
1st Normal Form: No
repeating groups
• Can't use equality to match elements
Name
Lumia
iPad
Galaxy
Categories
“electronics,hand held, smart phone”
“PDA,tablet”
“smart phone,tablet”
Product_id
1234
5678
91011
Maker
Nokia
Apple
Samsung
1st Normal Form: No
repeating groups
• Can't use equality to match elements
• Must use regular expressions to find data
Name
Lumia
iPad
Galaxy
Categories
“electronics,hand held, smart phone”
“PDA,tablet”
“smart phone,tablet”
Product_id
1234
5678
91011
Maker
Nokia
Apple
Samsung
1st Normal Form: No
repeating groups
• Can't use equality to match elements
• Must use regular expressions to find data
• Aggregate functions are difficult
Name
Lumia
iPad
Galaxy
Categories
“electronics,hand held, smart phone”
“PDA,tablet”
“smart phone,tablet”
Product_id
1234
5678
91011
Maker
Nokia
Apple
Samsung
1st Normal Form: No
repeating groups
• Can't use equality to match elements
• Must use regular expressions to find data
• Aggregate functions are difficult
• Updating a specific element is difficult
Name
Lumia
iPad
Galaxy
Categories
“electronics,hand held, smart phone”
“PDA,tablet”
“smart phone,tablet”
Product_id
1234
5678
91011
Maker
Nokia
Apple
Samsung
The Tao of MongoDB
{ _id : ObjectId(),
maker : “Nokia”
name : “Lumia”,
categories : [
"electronics",
"handheld",
"smart phone"
]
}
The Tao of MongoDB
{ _id : ObjectId(),
maker : “Nokia”
name : “Lumia”,
categories : [
"electronics",
"handheld",
"smart phone"
]
}
// querying is easy
db.products.find( { "categories": ”handheld" } );
The Tao of MongoDB
{ _id : ObjectId(),
maker : “Nokia”
name : “Lumia”,
categories : [
"electronics",
"handheld",
"smart phone"
]
}
// querying is easy
db.products.find( { "categories": ”handheld" } );
// can be indexed
db.products.ensureIndex( { "categories”: 1 } );
The Tao of MongoDB
{ _id : ObjectId(),
maker : “Nokia”
name : “Lumia”,
categories : [
"electronics",
"handheld",
"smart phone"
]
}
// Updates are easy
db.products.update(
{ "categories": "electronics"},
{ $set: { "categories.$" : "consumer electronics" } }
);
The Tao of MongoDB
{ _id : ObjectId(),
maker : “Nokia”
name : “Lumia”,
categories : [
"electronics",
"handheld",
"smart phone"
]
}
db.products.aggregate(
{ $unwind : "$categories" },
{ $group : {
"_id" : "$categories", "counts" : { "$sum" : 1 }
}
}
);
The Tao of MongoDB
{ _id : ObjectId(),
maker : “Nokia”
name : “Lumia”,
categories : [
"electronics",
"handheld",
"smart phone"
]
}
db.products.aggregate(
{ $unwind : "$categories" },
{ $group : {
"_id" : "$categories", "counts" : { "$sum" : 1 }
}
}
);
Unwind the array
The Tao of MongoDB
{ _id : ObjectId(),
maker : “Nokia”
name : “Lumia”,
categories : [
"electronics",
"handheld",
"smart phone"
]
}
db.products.aggregate(
{ $unwind : "$categories" },
{ $group : {
"_id" : "$categories", "counts" : { "$sum" : 1 }
}
}
);
Unwind the array
Tally the occurrences
The Tao of MongoDB
"result" : [
{ "_id" : "smart phone”, "counts" : 1589 },
{ "_id" : "handheld”, "counts" : 2403 },
{ "_id" : "electronics”, "counts" : 4767 }
]
db.products.aggregate(
{ $unwind : "$categories" },
{ $group : {
"_id" : "$categories", "counts" : { "$sum" : 1 }
}
}
);
Meh, big deal…. Right?
Aren’t nested structures just a pre-joined schema?
• I could use an adjacency list
• I could use an intersection table
Goals of Normalization
• Model data an understandable form
• Reduce fact redundancy and data
inconsistency
• Enforce integrity constraints
Performance is not a primary
goal
Normalize or Denormalize
Commonly held that denormalization is faster
Normalize or Denormalize
Commonly held that denormalization is faster
• Normalization can be fast, right?
Normalize or Denormalize
Commonly held that denormalization is faster
• Normalization can be fast, right? Requires
proper indexing, indexing effects write
performance
Normalize or Denormalize
Commonly held that denormalization is faster
• Normalization can be fast, right? Requires
proper indexing, indexing effects write
performance
• Does denormalization commit me to a join
strategy?
Normalize or Denormalize
Commonly held that denormalization is faster
• Normalization can be fast, right? Requires
proper indexing, indexing effects write
performance
• Does denormalization commit me to a join
strategy? Indexing overhead is a commitment
too
Normalize or Denormalize
Commonly held that denormalization is faster
• Normalization can be fast, right? Requires
proper indexing, indexing effects write
performance
• Does denormalization commit me to a join
strategy? Indexing overhead is a commitment
too
• Does denormalizaiton improve a finite set of
queries at the cost of several others?
Normalize or Denormalize
Commonly held that denormalization is faster
• Normalization can be fast, right? Requires
proper indexing, indexing effects write
performance
• Does denormalization commit me to a join
strategy? Indexing overhead is a commitment
too
• Does denormalizaiton improve a finite set of
queries at the cost of several others? MongoDB
works best in service to an application
Object–Relational
Impedance Mismatch
• Inheritance hierarchies
• Polymorphic associations
Table Per Subclass
Vehicles
vin
registration
maker
Motorcycle
Engine
rake
trial Racebike
racing number
class
team
rider
Table Per Subclass
Vehicles
- electric
- car
- bus
- motorcycle
- internal combustion
-motorcycle
- aircraft
- human powered
- bicycle
- skateboard
-horsedrawn
Table Per Concrete Class
• Each class is mapped to a separate table
• Inherited fields are present in each class’ table
• Can’t support polymorphic relationships
Table Per Concrete Class
• Each class is mapped to a separate table
• Inherited fields are present in each class’ table
• Can’t support polymorphic relationships
SELECT maker FROM Motorcycles WHERE Motorcycles.country =
"Italy"
UNION
SELECT maker FROM Automobiles WHERE Automobiles.country =
"Italy"
Table Per Class Family
• Classes mapped to a single table
Name
F4
A104
Triton 95
Type
sportbike
helicopter
submarine
Vehicle_id
1234
5678
91011
Maker
M.V
Agusta
M.V.
Agusta
Triton
Table Per Class Family
• Classes mapped to a single table
• Discriminator column to identify class
discriminator
Name
F4
A104
Triton 95
Type
sportbike
helicopter
submarine
Vehicle_id
1234
5678
91011
Maker
M.V
Agusta
M.V.
Agusta
Triton
Table Per Class Family
• Classes mapped to a single table
• Discriminator column to identify class
• Many empty columns, nullability issues
Name
F4
A104
Triton 95
Type
sportbike
helicopter
submarine
Vehicle_id
1234
5678
91011
Maker
M.V
Agusta
M.V.
Agusta
Triton
Table Per Class Family
• Classes mapped to a single table
• Discriminator column to identify class
• Many empty columns, nullability issues
maker = “M.V.
Agusta”,
type = “sportbike”,
num_doors = 0,
wing_area = 0,
maximum_depth = 0
???Name
F4
A104
Triton 95
Type
sportbike
helicopter
submarine
Vehicle_id
1234
5678
91011
Maker
M.V
Agusta
M.V.
Agusta
Triton
The Tao of MongoDB
{ maker : "M.V. Agusta",
type : sportsbike,
engine : {
type : ”internal combustion",
cylinders: 4,
displacement : 750
},
rake : 7,
trail : 3.93
}
{ maker : "M.V. Agusta",
type : Helicopter
engine : {
type : "turboshaft"
layout : "axial”,
massflow : 1318
},
Blades : 4
undercarriage : "fixed"
}
The Tao of MongoDB
{ maker : "M.V. Agusta",
type : sportsbike,
engine : {
type : ”internal combustion",
cylinders: 4,
displacement : 750
},
rake : 7,
trail : 3.93
}
{ maker : "M.V. Agusta",
type : Helicopter,
engine : {
type : "turboshaft"
layout : "axial”,
massflow : 1318
},
Blades : 4,
undercarriage : "fixed"
}
Discriminator column
The Tao of MongoDB
{ maker : "M.V. Agusta",
type : sportsbike,
engine : {
type : ”internal combustion",
cylinders: 4,
displacement : 750
},
rake : 7,
trail : 3.93
}
{ maker : "M.V. Agusta",
type : Helicopter
engine : {
type : "turboshaft"
layout : "axial”,
massflow : 1318
},
Blades : 4,
undercarriage : "fixed"
}
Shared indexing strategy
The Tao of MongoDB
{ maker : "M.V. Agusta",
type : sportsbike,
engine : {
type : ”internal combustion",
cylinders: 4,
displacement : 750
},
rake : 7,
trail : 3.93
}
{ maker : "M.V. Agusta",
type : Helicopter
engine : {
type : "turboshaft"
layout : "axial”,
massflow : 1318
},
Blades : 4
undercarriage : "fixed"
}
Polymorphic attributes
Relaxed ACID
• Atomic operations at the Document level
Relaxed ACID
• Atomic operations at the Document level
• Consistency – strong / eventual
Replication
Relaxed ACID
• Atomic operations at the Document level
• Consistency – strong / eventual
• Isolation - read lock, write lock / logical
database
Relaxed ACID
• Atomic operations at the Document level
• Consistency – strong / eventual
• Isolation - read lock, write lock / logical
database
• Durability – write ahead journal,
replication
The Tao of MongoDB
• Document database
• Flexible schema
• Relaxed ACID
This favors denormalization.
What’s the consequence?
Scaling MongoDB
Client
Application
Single Instance
Or
Replica Set
MongoDB
Sharded cluster
Partitioning
• User defines shard key
• Shard key defines range of data
• Key space is like points on a line
• Range is a segment of that line
The Mechanism of Sharding
Complete Data Set
Define shard key on vehicle id
3456 56781234 45672345
The Mechanism of Sharding
Chunk Chunk
Define shard key on title
3456 56781234 45672345
The Mechanism of Sharding
Chunk Chunk ChunkChunk
Define shard key on vehicle id
3456 56781234 45672345
Chunk Chunk ChunkChunk
Shard 1 Shard 2 Shard 3 Shard 4
3456 56781234 45672345
Define shard key on vehicle id
Shard 1 Shard 2 Shard 3 Shard 4
Targeted
Operations
Client
mongos
Shard 1 Shard 2 Shard 3 Shard 4
Data Growth
Shard 1 Shard 2 Shard 3 Shard 4
Load Balancing
Relational if you need to
• Enforce data constraints
• Service a broad set of queries
• Minimize redundancy
The Tao of MongoDB
• Avoid ad-hoc queries
• Model data for use, not storage
• Index effectively, index efficiently
Engineer, 10gen
Bryan Reinero
@blimpyacht
Thank You

Mais conteúdo relacionado

Destaque

Design and Implementation of Relational Database Design Tool
Design and Implementation of Relational Database Design ToolDesign and Implementation of Relational Database Design Tool
Design and Implementation of Relational Database Design Tool
talk2harry
 
Rim Based Relational Database Design Tutorial September 2008
Rim Based Relational Database Design Tutorial September 2008Rim Based Relational Database Design Tutorial September 2008
Rim Based Relational Database Design Tutorial September 2008
Abdul-Malik Shakir
 
Entity Attribute Value (Eav)
Entity   Attribute   Value (Eav)Entity   Attribute   Value (Eav)
Entity Attribute Value (Eav)
Tâm
 
Logical database design and the relational model(database)
Logical database design and the relational model(database)Logical database design and the relational model(database)
Logical database design and the relational model(database)
welcometofacebook
 
7. Relational Database Design in DBMS
7. Relational Database Design in DBMS7. Relational Database Design in DBMS
7. Relational Database Design in DBMS
koolkampus
 

Destaque (11)

Денис Резник "Relational Database Design. Normalize till it hurts, then Denor...
Денис Резник "Relational Database Design. Normalize till it hurts, then Denor...Денис Резник "Relational Database Design. Normalize till it hurts, then Denor...
Денис Резник "Relational Database Design. Normalize till it hurts, then Denor...
 
Design and Implementation of Relational Database Design Tool
Design and Implementation of Relational Database Design ToolDesign and Implementation of Relational Database Design Tool
Design and Implementation of Relational Database Design Tool
 
Eav Data Model Concepts
Eav Data Model ConceptsEav Data Model Concepts
Eav Data Model Concepts
 
Rim Based Relational Database Design Tutorial September 2008
Rim Based Relational Database Design Tutorial September 2008Rim Based Relational Database Design Tutorial September 2008
Rim Based Relational Database Design Tutorial September 2008
 
Understanding Linked Data via EAV Model based Structured Descriptions
Understanding Linked Data via EAV Model based Structured DescriptionsUnderstanding Linked Data via EAV Model based Structured Descriptions
Understanding Linked Data via EAV Model based Structured Descriptions
 
Entity Attribute Value (Eav)
Entity   Attribute   Value (Eav)Entity   Attribute   Value (Eav)
Entity Attribute Value (Eav)
 
Relational Database Design
Relational Database DesignRelational Database Design
Relational Database Design
 
Logical database design and the relational model(database)
Logical database design and the relational model(database)Logical database design and the relational model(database)
Logical database design and the relational model(database)
 
Anomalies in database
Anomalies in databaseAnomalies in database
Anomalies in database
 
7. Relational Database Design in DBMS
7. Relational Database Design in DBMS7. Relational Database Design in DBMS
7. Relational Database Design in DBMS
 
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
Relational Database Design - Lecture 4 - Introduction to Databases (1007156ANR)
 

Semelhante a Webinar: From Relational Databases to MongoDB - What You Need to Know

An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
Gavin Roy
 

Semelhante a Webinar: From Relational Databases to MongoDB - What You Need to Know (20)

Webinar: From Relational Databases to MongoDB - What You Need to Know
Webinar: From Relational Databases to MongoDB - What You Need to KnowWebinar: From Relational Databases to MongoDB - What You Need to Know
Webinar: From Relational Databases to MongoDB - What You Need to Know
 
Webinar: MongoDB and Polyglot Persistence Architecture
Webinar: MongoDB and Polyglot Persistence ArchitectureWebinar: MongoDB and Polyglot Persistence Architecture
Webinar: MongoDB and Polyglot Persistence Architecture
 
Polyglot Persistence
Polyglot PersistencePolyglot Persistence
Polyglot Persistence
 
Retail referencearchitecture productcatalog
Retail referencearchitecture productcatalogRetail referencearchitecture productcatalog
Retail referencearchitecture productcatalog
 
Introduction to Azure DocumentDB
Introduction to Azure DocumentDBIntroduction to Azure DocumentDB
Introduction to Azure DocumentDB
 
David Bilík: Anko – modern way to build your layouts?
David Bilík: Anko – modern way to build your layouts?David Bilík: Anko – modern way to build your layouts?
David Bilík: Anko – modern way to build your layouts?
 
Oracle PIM: Phantasmal Item Descriptions in your Organization
Oracle PIM: Phantasmal Item Descriptions in your OrganizationOracle PIM: Phantasmal Item Descriptions in your Organization
Oracle PIM: Phantasmal Item Descriptions in your Organization
 
MongoDB 3.4 webinar
MongoDB 3.4 webinarMongoDB 3.4 webinar
MongoDB 3.4 webinar
 
Webinar: Scaling MongoDB
Webinar: Scaling MongoDBWebinar: Scaling MongoDB
Webinar: Scaling MongoDB
 
Writing an extensible web testing framework ready for the cloud slide share
Writing an extensible web testing framework ready for the cloud   slide shareWriting an extensible web testing framework ready for the cloud   slide share
Writing an extensible web testing framework ready for the cloud slide share
 
Dataweek-Talk-2014
Dataweek-Talk-2014Dataweek-Talk-2014
Dataweek-Talk-2014
 
Simplifying & accelerating application development with MongoDB's intelligent...
Simplifying & accelerating application development with MongoDB's intelligent...Simplifying & accelerating application development with MongoDB's intelligent...
Simplifying & accelerating application development with MongoDB's intelligent...
 
MongoDB
MongoDBMongoDB
MongoDB
 
Mongo DB
Mongo DB Mongo DB
Mongo DB
 
Elasticsearch intro output
Elasticsearch intro outputElasticsearch intro output
Elasticsearch intro output
 
An Introduction to Tornado
An Introduction to TornadoAn Introduction to Tornado
An Introduction to Tornado
 
Le big data à l'épreuve des projets d'entreprise
Le big data à l'épreuve des projets d'entrepriseLe big data à l'épreuve des projets d'entreprise
Le big data à l'épreuve des projets d'entreprise
 
کارگاه سئو
کارگاه سئوکارگاه سئو
کارگاه سئو
 
How to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better PerformanceHow to Analyze and Tune MySQL Queries for Better Performance
How to Analyze and Tune MySQL Queries for Better Performance
 
ElasticSearch Hands On
ElasticSearch Hands OnElasticSearch Hands On
ElasticSearch Hands On
 

Mais de MongoDB

Mais de MongoDB (20)

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB AtlasMongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDBMongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series DataMongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 MongoDB SoCal 2020: MongoDB Atlas Jump Start MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
 
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
 
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your MindsetMongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas JumpstartMongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
 
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep DiveMongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & GolangMongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 

Último (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024Top 10 Most Downloaded Games on Play Store in 2024
Top 10 Most Downloaded Games on Play Store in 2024
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 

Webinar: From Relational Databases to MongoDB - What You Need to Know

  • 2. Unhelpful Terms • NoSQL • Big Data • Distributed What’s the data model?
  • 3. MongoDB • Non-relational • Scalable • Highly available • Full featured • Document database
  • 4. RDBMS MongoDB Table, View ➜ Collection Row ➜ Document Index ➜ Index Join ➜ Embedded Document Foreign Key ➜ Reference Partition ➜ Shard Terminology
  • 5. Sample Document { maker : "M.V. Agusta", type : sportbike, rake : 7, trail : 3.93, engine : { type : "internal cumbustion", layout : "inline" cylinders : 4, displacement : 750, }, transmission : { type : "cassette", speeds : 6, pattern : "sequential”, ratios : [ 2.7, 1.94, 1.34, 1, 0.83, 0.64 ] } }
  • 6. Relational DBs • Attribute columns are valid for every row • Duplicate rows are not allowed • Every column has the same type and same meaning As a document store, MongoDB supports a flexible schema
  • 7. 1st Normal Form: No repeating groups • Can't use equality to match elements Name Lumia iPad Galaxy Categories “electronics,hand held, smart phone” “PDA,tablet” “smart phone,tablet” Product_id 1234 5678 91011 Maker Nokia Apple Samsung
  • 8. 1st Normal Form: No repeating groups • Can't use equality to match elements • Must use regular expressions to find data Name Lumia iPad Galaxy Categories “electronics,hand held, smart phone” “PDA,tablet” “smart phone,tablet” Product_id 1234 5678 91011 Maker Nokia Apple Samsung
  • 9. 1st Normal Form: No repeating groups • Can't use equality to match elements • Must use regular expressions to find data • Aggregate functions are difficult Name Lumia iPad Galaxy Categories “electronics,hand held, smart phone” “PDA,tablet” “smart phone,tablet” Product_id 1234 5678 91011 Maker Nokia Apple Samsung
  • 10. 1st Normal Form: No repeating groups • Can't use equality to match elements • Must use regular expressions to find data • Aggregate functions are difficult • Updating a specific element is difficult Name Lumia iPad Galaxy Categories “electronics,hand held, smart phone” “PDA,tablet” “smart phone,tablet” Product_id 1234 5678 91011 Maker Nokia Apple Samsung
  • 11. The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] }
  • 12. The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] } // querying is easy db.products.find( { "categories": ”handheld" } );
  • 13. The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] } // querying is easy db.products.find( { "categories": ”handheld" } ); // can be indexed db.products.ensureIndex( { "categories”: 1 } );
  • 14. The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] } // Updates are easy db.products.update( { "categories": "electronics"}, { $set: { "categories.$" : "consumer electronics" } } );
  • 15. The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] } db.products.aggregate( { $unwind : "$categories" }, { $group : { "_id" : "$categories", "counts" : { "$sum" : 1 } } } );
  • 16. The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] } db.products.aggregate( { $unwind : "$categories" }, { $group : { "_id" : "$categories", "counts" : { "$sum" : 1 } } } ); Unwind the array
  • 17. The Tao of MongoDB { _id : ObjectId(), maker : “Nokia” name : “Lumia”, categories : [ "electronics", "handheld", "smart phone" ] } db.products.aggregate( { $unwind : "$categories" }, { $group : { "_id" : "$categories", "counts" : { "$sum" : 1 } } } ); Unwind the array Tally the occurrences
  • 18. The Tao of MongoDB "result" : [ { "_id" : "smart phone”, "counts" : 1589 }, { "_id" : "handheld”, "counts" : 2403 }, { "_id" : "electronics”, "counts" : 4767 } ] db.products.aggregate( { $unwind : "$categories" }, { $group : { "_id" : "$categories", "counts" : { "$sum" : 1 } } } );
  • 19. Meh, big deal…. Right? Aren’t nested structures just a pre-joined schema? • I could use an adjacency list • I could use an intersection table
  • 20. Goals of Normalization • Model data an understandable form • Reduce fact redundancy and data inconsistency • Enforce integrity constraints Performance is not a primary goal
  • 21. Normalize or Denormalize Commonly held that denormalization is faster
  • 22. Normalize or Denormalize Commonly held that denormalization is faster • Normalization can be fast, right?
  • 23. Normalize or Denormalize Commonly held that denormalization is faster • Normalization can be fast, right? Requires proper indexing, indexing effects write performance
  • 24. Normalize or Denormalize Commonly held that denormalization is faster • Normalization can be fast, right? Requires proper indexing, indexing effects write performance • Does denormalization commit me to a join strategy?
  • 25. Normalize or Denormalize Commonly held that denormalization is faster • Normalization can be fast, right? Requires proper indexing, indexing effects write performance • Does denormalization commit me to a join strategy? Indexing overhead is a commitment too
  • 26. Normalize or Denormalize Commonly held that denormalization is faster • Normalization can be fast, right? Requires proper indexing, indexing effects write performance • Does denormalization commit me to a join strategy? Indexing overhead is a commitment too • Does denormalizaiton improve a finite set of queries at the cost of several others?
  • 27. Normalize or Denormalize Commonly held that denormalization is faster • Normalization can be fast, right? Requires proper indexing, indexing effects write performance • Does denormalization commit me to a join strategy? Indexing overhead is a commitment too • Does denormalizaiton improve a finite set of queries at the cost of several others? MongoDB works best in service to an application
  • 28. Object–Relational Impedance Mismatch • Inheritance hierarchies • Polymorphic associations
  • 30. Table Per Subclass Vehicles - electric - car - bus - motorcycle - internal combustion -motorcycle - aircraft - human powered - bicycle - skateboard -horsedrawn
  • 31. Table Per Concrete Class • Each class is mapped to a separate table • Inherited fields are present in each class’ table • Can’t support polymorphic relationships
  • 32. Table Per Concrete Class • Each class is mapped to a separate table • Inherited fields are present in each class’ table • Can’t support polymorphic relationships SELECT maker FROM Motorcycles WHERE Motorcycles.country = "Italy" UNION SELECT maker FROM Automobiles WHERE Automobiles.country = "Italy"
  • 33. Table Per Class Family • Classes mapped to a single table Name F4 A104 Triton 95 Type sportbike helicopter submarine Vehicle_id 1234 5678 91011 Maker M.V Agusta M.V. Agusta Triton
  • 34. Table Per Class Family • Classes mapped to a single table • Discriminator column to identify class discriminator Name F4 A104 Triton 95 Type sportbike helicopter submarine Vehicle_id 1234 5678 91011 Maker M.V Agusta M.V. Agusta Triton
  • 35. Table Per Class Family • Classes mapped to a single table • Discriminator column to identify class • Many empty columns, nullability issues Name F4 A104 Triton 95 Type sportbike helicopter submarine Vehicle_id 1234 5678 91011 Maker M.V Agusta M.V. Agusta Triton
  • 36. Table Per Class Family • Classes mapped to a single table • Discriminator column to identify class • Many empty columns, nullability issues maker = “M.V. Agusta”, type = “sportbike”, num_doors = 0, wing_area = 0, maximum_depth = 0 ???Name F4 A104 Triton 95 Type sportbike helicopter submarine Vehicle_id 1234 5678 91011 Maker M.V Agusta M.V. Agusta Triton
  • 37. The Tao of MongoDB { maker : "M.V. Agusta", type : sportsbike, engine : { type : ”internal combustion", cylinders: 4, displacement : 750 }, rake : 7, trail : 3.93 } { maker : "M.V. Agusta", type : Helicopter engine : { type : "turboshaft" layout : "axial”, massflow : 1318 }, Blades : 4 undercarriage : "fixed" }
  • 38. The Tao of MongoDB { maker : "M.V. Agusta", type : sportsbike, engine : { type : ”internal combustion", cylinders: 4, displacement : 750 }, rake : 7, trail : 3.93 } { maker : "M.V. Agusta", type : Helicopter, engine : { type : "turboshaft" layout : "axial”, massflow : 1318 }, Blades : 4, undercarriage : "fixed" } Discriminator column
  • 39. The Tao of MongoDB { maker : "M.V. Agusta", type : sportsbike, engine : { type : ”internal combustion", cylinders: 4, displacement : 750 }, rake : 7, trail : 3.93 } { maker : "M.V. Agusta", type : Helicopter engine : { type : "turboshaft" layout : "axial”, massflow : 1318 }, Blades : 4, undercarriage : "fixed" } Shared indexing strategy
  • 40. The Tao of MongoDB { maker : "M.V. Agusta", type : sportsbike, engine : { type : ”internal combustion", cylinders: 4, displacement : 750 }, rake : 7, trail : 3.93 } { maker : "M.V. Agusta", type : Helicopter engine : { type : "turboshaft" layout : "axial”, massflow : 1318 }, Blades : 4 undercarriage : "fixed" } Polymorphic attributes
  • 41. Relaxed ACID • Atomic operations at the Document level
  • 42. Relaxed ACID • Atomic operations at the Document level • Consistency – strong / eventual
  • 44. Relaxed ACID • Atomic operations at the Document level • Consistency – strong / eventual • Isolation - read lock, write lock / logical database
  • 45. Relaxed ACID • Atomic operations at the Document level • Consistency – strong / eventual • Isolation - read lock, write lock / logical database • Durability – write ahead journal, replication
  • 46. The Tao of MongoDB • Document database • Flexible schema • Relaxed ACID This favors denormalization. What’s the consequence?
  • 48. Partitioning • User defines shard key • Shard key defines range of data • Key space is like points on a line • Range is a segment of that line
  • 49. The Mechanism of Sharding Complete Data Set Define shard key on vehicle id 3456 56781234 45672345
  • 50. The Mechanism of Sharding Chunk Chunk Define shard key on title 3456 56781234 45672345
  • 51. The Mechanism of Sharding Chunk Chunk ChunkChunk Define shard key on vehicle id 3456 56781234 45672345
  • 52. Chunk Chunk ChunkChunk Shard 1 Shard 2 Shard 3 Shard 4 3456 56781234 45672345 Define shard key on vehicle id
  • 53. Shard 1 Shard 2 Shard 3 Shard 4 Targeted Operations Client mongos
  • 54. Shard 1 Shard 2 Shard 3 Shard 4 Data Growth
  • 55. Shard 1 Shard 2 Shard 3 Shard 4 Load Balancing
  • 56. Relational if you need to • Enforce data constraints • Service a broad set of queries • Minimize redundancy
  • 57. The Tao of MongoDB • Avoid ad-hoc queries • Model data for use, not storage • Index effectively, index efficiently

Notas do Editor

  1. 1970’s design normalization
  2. Base class mapped to separate tableSupports polymorphic relationshipsRequires joinsIsn’t practical to map every class to the parent
  3. If the hierarchy grows joins on every derived classIsn’t practical to map every class to the parent
  4. Closer to denormalizationUNION required to cover the entire inheritance
  5. Closer to denormalizationUNION required to cover the entire inheritance
  6. Independent node operations
  7. Independent node operations
  8. Independent node operations
  9. Independent node operations
  10. Independent node operations
  11. Multi-row documentation