SlideShare uma empresa Scribd logo
1 de 44
Baixar para ler offline
#MDBlocal
Austin Zellner
Practical Data Modelling
CHICAGO
#MDBLocal
Why MongoDB?
Best way to work
with data
Intelligently put data
where you need it
Freedom
to run anywhere
Intelligent Operational Data Platform
#MDBLocal
Data Modeling Refresher
Conceptual
• What are we capturing?
Logical
• What are the relationships?
Physical
• How do we want to store it?
#MDBLocal
Example: Customer & Address
Database
Index
MongoDB
Customer
Collection
Tables
Document
#MDBLocal
MongoDB Approach
Utility of data leveraged with through query and access pattern
Data
(BSON)
Query
( CRUD /
Aggregation
Pipeline )
Access
Pattern
( Indexing )
Utility
Data Model
Fundamentals
#MDBLocal
BSON Explored
Typed Data
Capture Field Value pairs, capture Arrays, capture Sub Documents
#MDBLocal
Easy: Document data model
• Naturally maps to objects in code
• Represent data of any structure
• Strongly typed for ease of processing
– Over 20 binary encoded JSON data types
• Access by idiomatic drivers in all
major programming language
{
"_id" : ObjectId("5ad88534e3632e1a35a58d00"),
"name" : {
"first" : "John",
"last" : "Doe" },
"address" : [
{ "location" : "work",
"address" : {
"street" : "16 Hatfields",
"city" : "London",
"postal_code" : "SE1 8DJ"},
"geo" : { "type" : "Point", "coord" : [
51.5065752,-0.109081]}},
+ {...}
],
"phone" : [
{ "location" : "work",
"number" : "+44-1234567890"},
+ {...}
],
"dob" : ISODate("1977-04-01T05:00:00Z"),
"retirement_fund" : NumberDecimal("1292815.75")
}
#MDBLocal
{
"_id" : ObjectId("5ad88534e3632e1a35a58d00"),
"name" : {
"first" : "John",
"last" : "Doe" },
"address" : [
{ "location" : "work",
"address" : {
"street" : "16 Hatfields",
"city" : "London",
"postal_code" : "SE1 8DJ"},
"geo" : { "type" : "Point", "coord" : [
51.5065752,-0.109081]}},
+ {...}
],
"dob" : ISODate("1977-04-01T05:00:00Z"),
"retirement_fund" : NumberDecimal("1292815.75")
}
Flexible: Adapt to change
Add new fields dynamically at runtime
{
"_id" : ObjectId("5ad88534e3632e1a35a58d00"),
"name" : {
"first" : "John",
"last" : "Doe" },
"address" : [
{ "location" : "work",
"address" : {
"street" : "16 Hatfields",
"city" : "London",
"postal_code" : "SE1 8DJ"},
"geo" : { "type" : "Point", "coord" : [
51.5065752,-0.109081]}},
+ {...}
],
"phone" : [
{ "location" : "work",
"number" : "+44-1234567890"},
+ {...}
],
"dob" : ISODate("1977-04-01T05:00:00Z"),
"retirement_fund" : NumberDecimal("1292815.75")
}
#MDBLocal
Versatile: Multiple data models
JSON Documents Tabular Key-Value Text GraphGeospatial
#MDBLocal
JSON
Stored directly into BSON
Most common entry point for
customers using MongoDB
#MDBLocal
Tabular ( Relational )
Capture column and value as Field Value pairs
Instead of left to right, top to bottom
Sub tables are captured as sub documents
#MDBLocal
Key Value
Key value captured directly as Field Value
If caching, can use TTL index
For attributes, exists as sub document
#MDBLocal
Text
Captured directly into Field Value
#MDBLocal
Graph
Captured in Array
{ "_id" : 0, "airport" : "JFK", "connects" : [ "BOS", "ORD" ] }
{ "_id" : 1, "airport" : "BOS", "connects" : [ "JFK", "PWM" ] }
{ "_id" : 2, "airport" : "ORD", "connects" : [ "JFK" ] }
{ "_id" : 3, "airport" : "PWM", "connects" : [ "BOS", "LHR" ] }
{ "_id" : 4, "airport" : "LHR", "connects" : [ "PWM" ] }
#MDBLocal
Geospatial
Stored in GeoJSON
<field>: { type: <GeoJSON type> , coordinates: <coordinates> }
Types: Point, LineString, Polygon, Multipoint, MultiLinestring, MultiPolygon,
GeometryCollection
Examples
• { type: "Point", coordinates: [ 40, 5 ] }
• { type: "LineString", coordinates: [ [ 40, 5 ], [ 41, 6 ] ] }
• {
type: "Polygon",
coordinates: [ [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ] ]
}
#MDBLocal
Combine Multiple Models in One Document
“storenumber” 101
“wifi_fence” type: "Polygon", coordinates: [ [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ] ]
“amenities”
“playland” Y
“curbside_pickup” Y
“delivery” Y
“storelocation” type: "Point", [ 123, 456 ]
“sister_stores” [ 102, 104, 503 ]
“description” MongoDB’s document model is…
“employees”
“name” Bob
“name” Sue
“name” Ed
Geo
Key:value
Text
Graph
Tabular
#MDBLocal
Combine Data and State in the Same Document
• Relational keeps data and state information separate
• MongoDB – combine data and state in same document
• Read stateful data from Primary, read stateless data from
Secondary
Querying
#MDBLocal
CRUD Operations
Create
• db.collection.insert( )
• db.collection.save( )
• db.collection.update( , , { upsert: true } )
Read
• db.collection.find( , )
• db.collection.findOne( , )
Update
• db.collection.update( , , )
Delete
• db.collection.remove( , )
#MDBLocal
db.customers.aggregate([
{
$unwind: "$address",
},
{
$match: {"address.location": "home"}
},
{
$group: {
_id: "$address.city",
totalSpend: {$sum: "$annualSpend"},
averageSpend: {$avg: "$annualSpend"},
maximumSpend: {$max: "$annualSpend"},
customers: {$sum: 1}
}
}
])
Versatile: Complex queries fast to create, optimize, & maintain
MongoDB’s aggregation framework has the flexibility you need to get
value from your data, but without the complexity and fragility of SQL
These “phases” are distinct and
easy to understand
They can be thought about in
order… no nesting.
#MDBLocal
Versatile: Rich query functionality
MongoDB
{ customer_id : 1,
first_name : "Mark",
last_name : "Smith",
city : "San Francisco",
phones: [ {
number : "1-212-777-1212",
type : "work"
},
{
number : "1-212-777-1213",
type : "cell"
}]
……...
Expressive
Queries
• Find anyone with phone # “1-212…”
• Check if the person with number “555…” is on the “do not call” list
Geospatial
• Find the best offer for the customer at geo coordinates of 42nd St.
and 6th Ave
Text Search • Find all tweets that mention the firm within the last 2 days
Aggregation
• Count and sort number of customers by city, compute min, max,
and average spend
Native Binary
JSON Support
• Add an additional phone number to Mark Smith’s record without
rewriting the document
• Update just 2 phone numbers out of 10
• Sort on the modified date
JOIN
($lookup)
• Query for all San Francisco residences, lookup their transactions,
and sum the amount by person
Graph Queries
($graphLookup)
• Query for all people within 3 degrees of separation from Mark
#MDBLocal
Aggregation to leverage Utility
#MDBLocal
Design Queries to express meaningfulness of data
Since we are layering multiple dimensions, leverage queries to
express the concepts represented in the data.
Example:
Customer Information
Address Information
State in System
Metadata for reporting
Query – Represent customer
and address
Query – Get status
Query – Pull data for reporting
CRUD – Get All
Indexing
#MDBLocal
Types of indexes
Compound Index
Single Field Index
Text Index
Geospatial Index (lat/lon pairs)
Unique Index (ensures uniqueness)
TTL Index (Time To Live - automatically delete
after elapsed time)
#MDBLocal
Fully Indexable
Fully featured secondary indexes
• Primary Index
– Every Collection has a primary key index
• Compound Index
– Index against multiple keys in the document
• MultiKey Index
– Index into arrays
• Wildcard Index
– Auto-index all matching fields, sub-documents &
arrays
• Text Indexes
– Support for text searches
• GeoSpatial Indexes
– 2d & 2dSphere indexes for spatial geometries
• Hashed Indexes
– Hashed based values for sharding
Index Types
• TTL Indexes
– Single Field indexes, when expired delete the document
• Unique Indexes
– Ensures value is not duplicated
• Partial Indexes
– Expression based indexes, allowing indexes on subsets of data
• Case Insensitive Indexes
• supports text search using case insensitive search
• Sparse Indexes
– Only index documents which have the given field
Index Features
#MDBLocal
{
"_id" : ObjectId("5c1d358bf383fbee028aea0b"),
"product_name" : "Blaster Gauntlet",
"product_attributes" : {
"elements" : [ "Fire" , "Water" ],
"price" : 250
...
}
},
{
"_id" : ObjectId("5c1d358bf383fbee028aea0c"),
"product_name" : "Super Suit",
"product_attributes" : {
"superFlight" : true,
"resistance" : [ "Bludgeoning", "Piercing", "Slashing" ]
...
},
}
Wildcard Indexes
Allow more natural data modeling, avoids
pre-defining indexes for every access
pattern
• Polymorphic document structures:
Product catalogs, CMS
• Ad-hoc queries & data exploration
Define a filter that indexes all matching fields,
sub-documents, and arrays
• Sparse index, omit specific fields
• Covered queries & collations
• Strongly consistent: updated
atomically with base data
Index all sub-documents &
arrays under Product Attributes
#MDBLocal
Special place for
those who do not
Index…
Design Patterns
#MDBLocal
MongoDB Approach
Utility of data leveraged with through query and access pattern
Data
(BSON)
Query
( CRUD /
Aggregation
Pipeline )
Access
Pattern
( Indexing )
Utility
#MDBLocal
One Big Document
Use Case A
Use Case B
Use Case C
#MDBLocal
Application Specific Domain
Customer
Orders
Status
Customer
Orders
Inventory
Focus from Customer point of view
OK because logical relationships flow
This problematic, because Inventory
should be in it’s own logical domain…
#MDBLocal
Easy: MongoDB Multi-Document ACID Transactions
Just like relational transactions
• Multi-statement, familiar relational syntax
• Easy to add to any application
• Multiple documents in 1 or many collections and databases
ACID guarantees
• Snapshot isolation, all or nothing execution
• No performance impact for non-transactional operations
#MDBLocal
Syntax
with client.start_session() as s:
s.start_transaction()
collection_one.insert_one(doc_one, session=s)
collection_two.insert_one(doc_two, session=s)
s.commit_transaction()
Natural for developers
• Idiomatic to the programming
language
• Familiar to relational
developers
• Simple
#MDBLocal
Master and Working Collections
Master: Customer
Order
Use
Case
Working: Order
Read
Read/Write
Master: Inventory
Read
• Master collections are stateless
• Working collections are stateful
• When initiate working document,
read as needed from Master
• Duplicate only for performance
• When Working state changes,
write back to Master
• Example: inventory consumed
• If duplicated data changes in Master,
write update to Working file
• Example: shipping address
• Use Transactions to keep it all straight
1
1
2
2
#MDBLocal
https://university.mongodb.com/courses/M320/about
Data Modeling Patterns Use Cases
Q&A
#MDBlocal
Practical Data Modeling
for MongoDB: Tutorial
https://www.surveymonkey.com/r/6GZ2GQR
Every session you rate enters you into a drawing for a $250
Visa gift card, sponsored by
THANK YOU

Mais conteúdo relacionado

Mais procurados

User Data Management with MongoDB
User Data Management with MongoDB User Data Management with MongoDB
User Data Management with MongoDB
MongoDB
 

Mais procurados (20)

Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
 
MongoDB .local Chicago 2019: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local Chicago 2019: From SQL to NoSQL -- Changing Your MindsetMongoDB .local Chicago 2019: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local Chicago 2019: From SQL to NoSQL -- Changing Your Mindset
 
Joins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation EnhancementsJoins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation Enhancements
 
MongoDB .local Paris 2020: Tout savoir sur le moteur de recherche Full Text S...
MongoDB .local Paris 2020: Tout savoir sur le moteur de recherche Full Text S...MongoDB .local Paris 2020: Tout savoir sur le moteur de recherche Full Text S...
MongoDB .local Paris 2020: Tout savoir sur le moteur de recherche Full Text S...
 
Deciphering Explain Output
Deciphering Explain Output Deciphering Explain Output
Deciphering Explain Output
 
Webinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and JavaWebinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and Java
 
MongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and ImplicationsMongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and Implications
 
Webinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDBWebinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDB
 
MongoDB .local Chicago 2019: Still Haven't Found What You Are Looking For? Us...
MongoDB .local Chicago 2019: Still Haven't Found What You Are Looking For? Us...MongoDB .local Chicago 2019: Still Haven't Found What You Are Looking For? Us...
MongoDB .local Chicago 2019: Still Haven't Found What You Are Looking For? Us...
 
MongoDB Meetup
MongoDB MeetupMongoDB Meetup
MongoDB Meetup
 
MongoDB Stich Overview
MongoDB Stich OverviewMongoDB Stich Overview
MongoDB Stich Overview
 
N1QL workshop: Indexing & Query turning.
N1QL workshop: Indexing & Query turning.N1QL workshop: Indexing & Query turning.
N1QL workshop: Indexing & Query turning.
 
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDBMongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
 
High Performance Applications with MongoDB
High Performance Applications with MongoDBHigh Performance Applications with MongoDB
High Performance Applications with MongoDB
 
MongodB Internals
MongodB InternalsMongodB Internals
MongodB Internals
 
Python and MongoDB as a Market Data Platform by James Blackburn
Python and MongoDB as a Market Data Platform by James BlackburnPython and MongoDB as a Market Data Platform by James Blackburn
Python and MongoDB as a Market Data Platform by James Blackburn
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB ApplicationBack to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
 
User Data Management with MongoDB
User Data Management with MongoDB User Data Management with MongoDB
User Data Management with MongoDB
 
MongoDB Europe 2016 - Who’s Helping Themselves To Your Data? Demystifying Mon...
MongoDB Europe 2016 - Who’s Helping Themselves To Your Data? Demystifying Mon...MongoDB Europe 2016 - Who’s Helping Themselves To Your Data? Demystifying Mon...
MongoDB Europe 2016 - Who’s Helping Themselves To Your Data? Demystifying Mon...
 
Getting to Insights Faster with the MongoDB Connector for BI
Getting to Insights Faster with the MongoDB Connector for BIGetting to Insights Faster with the MongoDB Connector for BI
Getting to Insights Faster with the MongoDB Connector for BI
 

Semelhante a MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial

Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
Murat Çakal
 
MongoDB Schema Design
MongoDB Schema DesignMongoDB Schema Design
MongoDB Schema Design
Alex Litvinok
 

Semelhante a MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial (20)

Data Analytics with MongoDB - Jane Fine
Data Analytics with MongoDB - Jane FineData Analytics with MongoDB - Jane Fine
Data Analytics with MongoDB - Jane Fine
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local London 2019: Best Practices for Working with IoT and Time-seri...
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
MongoDB .local Paris 2020: Les bonnes pratiques pour travailler avec les donn...
MongoDB .local Paris 2020: Les bonnes pratiques pour travailler avec les donn...MongoDB .local Paris 2020: Les bonnes pratiques pour travailler avec les donn...
MongoDB .local Paris 2020: Les bonnes pratiques pour travailler avec les donn...
 
Introduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUWIntroduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUW
 
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...
 
tranSMART Community Meeting 5-7 Nov 13 - Session 2: MongoDB: What, Why And When
tranSMART Community Meeting 5-7 Nov 13 - Session 2: MongoDB: What, Why And WhentranSMART Community Meeting 5-7 Nov 13 - Session 2: MongoDB: What, Why And When
tranSMART Community Meeting 5-7 Nov 13 - Session 2: MongoDB: What, Why And When
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
 
MongoDB NoSQL database a deep dive -MyWhitePaper
MongoDB  NoSQL database a deep dive -MyWhitePaperMongoDB  NoSQL database a deep dive -MyWhitePaper
MongoDB NoSQL database a deep dive -MyWhitePaper
 
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDBMongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
MongoDB.local DC 2018: Tutorial - Data Analytics with MongoDB
 
[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch
[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch
[MongoDB.local Bengaluru 2018] Introduction to MongoDB Stitch
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
MongoDB .local Chicago 2019: Best Practices for Working with IoT and Time-ser...
MongoDB .local Chicago 2019: Best Practices for Working with IoT and Time-ser...MongoDB .local Chicago 2019: Best Practices for Working with IoT and Time-ser...
MongoDB .local Chicago 2019: Best Practices for Working with IoT and Time-ser...
 
NoSQL Data Modeling using Couchbase
NoSQL Data Modeling using CouchbaseNoSQL Data Modeling using Couchbase
NoSQL Data Modeling using Couchbase
 
Fast querying indexing for performance (4)
Fast querying   indexing for performance (4)Fast querying   indexing for performance (4)
Fast querying indexing for performance (4)
 
Storage dei dati con MongoDB
Storage dei dati con MongoDBStorage dei dati con MongoDB
Storage dei dati con MongoDB
 
MongoDB.pdf
MongoDB.pdfMongoDB.pdf
MongoDB.pdf
 
MongoDB Schema Design
MongoDB Schema DesignMongoDB Schema Design
MongoDB Schema Design
 
Meetup#2: MongoDB Schema Design
Meetup#2: MongoDB Schema DesignMeetup#2: MongoDB Schema Design
Meetup#2: MongoDB Schema Design
 

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: 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: 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...
 
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
MongoDB .local Paris 2020: Adéo @MongoDB : MongoDB Atlas & Leroy Merlin : et ...
 
MongoDB .local Paris 2020: Devenez explorateur de données avec MongoDB Charts
MongoDB .local Paris 2020: Devenez explorateur de données avec MongoDB ChartsMongoDB .local Paris 2020: Devenez explorateur de données avec MongoDB Charts
MongoDB .local Paris 2020: Devenez explorateur de données avec MongoDB Charts
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
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)

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
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
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
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
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
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 

MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial

  • 2.
  • 3.
  • 4.
  • 5.
  • 6. #MDBLocal Why MongoDB? Best way to work with data Intelligently put data where you need it Freedom to run anywhere Intelligent Operational Data Platform
  • 7. #MDBLocal Data Modeling Refresher Conceptual • What are we capturing? Logical • What are the relationships? Physical • How do we want to store it?
  • 8. #MDBLocal Example: Customer & Address Database Index MongoDB Customer Collection Tables Document
  • 9. #MDBLocal MongoDB Approach Utility of data leveraged with through query and access pattern Data (BSON) Query ( CRUD / Aggregation Pipeline ) Access Pattern ( Indexing ) Utility
  • 11. #MDBLocal BSON Explored Typed Data Capture Field Value pairs, capture Arrays, capture Sub Documents
  • 12. #MDBLocal Easy: Document data model • Naturally maps to objects in code • Represent data of any structure • Strongly typed for ease of processing – Over 20 binary encoded JSON data types • Access by idiomatic drivers in all major programming language { "_id" : ObjectId("5ad88534e3632e1a35a58d00"), "name" : { "first" : "John", "last" : "Doe" }, "address" : [ { "location" : "work", "address" : { "street" : "16 Hatfields", "city" : "London", "postal_code" : "SE1 8DJ"}, "geo" : { "type" : "Point", "coord" : [ 51.5065752,-0.109081]}}, + {...} ], "phone" : [ { "location" : "work", "number" : "+44-1234567890"}, + {...} ], "dob" : ISODate("1977-04-01T05:00:00Z"), "retirement_fund" : NumberDecimal("1292815.75") }
  • 13. #MDBLocal { "_id" : ObjectId("5ad88534e3632e1a35a58d00"), "name" : { "first" : "John", "last" : "Doe" }, "address" : [ { "location" : "work", "address" : { "street" : "16 Hatfields", "city" : "London", "postal_code" : "SE1 8DJ"}, "geo" : { "type" : "Point", "coord" : [ 51.5065752,-0.109081]}}, + {...} ], "dob" : ISODate("1977-04-01T05:00:00Z"), "retirement_fund" : NumberDecimal("1292815.75") } Flexible: Adapt to change Add new fields dynamically at runtime { "_id" : ObjectId("5ad88534e3632e1a35a58d00"), "name" : { "first" : "John", "last" : "Doe" }, "address" : [ { "location" : "work", "address" : { "street" : "16 Hatfields", "city" : "London", "postal_code" : "SE1 8DJ"}, "geo" : { "type" : "Point", "coord" : [ 51.5065752,-0.109081]}}, + {...} ], "phone" : [ { "location" : "work", "number" : "+44-1234567890"}, + {...} ], "dob" : ISODate("1977-04-01T05:00:00Z"), "retirement_fund" : NumberDecimal("1292815.75") }
  • 14. #MDBLocal Versatile: Multiple data models JSON Documents Tabular Key-Value Text GraphGeospatial
  • 15. #MDBLocal JSON Stored directly into BSON Most common entry point for customers using MongoDB
  • 16. #MDBLocal Tabular ( Relational ) Capture column and value as Field Value pairs Instead of left to right, top to bottom Sub tables are captured as sub documents
  • 17. #MDBLocal Key Value Key value captured directly as Field Value If caching, can use TTL index For attributes, exists as sub document
  • 19. #MDBLocal Graph Captured in Array { "_id" : 0, "airport" : "JFK", "connects" : [ "BOS", "ORD" ] } { "_id" : 1, "airport" : "BOS", "connects" : [ "JFK", "PWM" ] } { "_id" : 2, "airport" : "ORD", "connects" : [ "JFK" ] } { "_id" : 3, "airport" : "PWM", "connects" : [ "BOS", "LHR" ] } { "_id" : 4, "airport" : "LHR", "connects" : [ "PWM" ] }
  • 20. #MDBLocal Geospatial Stored in GeoJSON <field>: { type: <GeoJSON type> , coordinates: <coordinates> } Types: Point, LineString, Polygon, Multipoint, MultiLinestring, MultiPolygon, GeometryCollection Examples • { type: "Point", coordinates: [ 40, 5 ] } • { type: "LineString", coordinates: [ [ 40, 5 ], [ 41, 6 ] ] } • { type: "Polygon", coordinates: [ [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ] ] }
  • 21. #MDBLocal Combine Multiple Models in One Document “storenumber” 101 “wifi_fence” type: "Polygon", coordinates: [ [ [ 0 , 0 ] , [ 3 , 6 ] , [ 6 , 1 ] , [ 0 , 0 ] ] ] “amenities” “playland” Y “curbside_pickup” Y “delivery” Y “storelocation” type: "Point", [ 123, 456 ] “sister_stores” [ 102, 104, 503 ] “description” MongoDB’s document model is… “employees” “name” Bob “name” Sue “name” Ed Geo Key:value Text Graph Tabular
  • 22. #MDBLocal Combine Data and State in the Same Document • Relational keeps data and state information separate • MongoDB – combine data and state in same document • Read stateful data from Primary, read stateless data from Secondary
  • 24. #MDBLocal CRUD Operations Create • db.collection.insert( ) • db.collection.save( ) • db.collection.update( , , { upsert: true } ) Read • db.collection.find( , ) • db.collection.findOne( , ) Update • db.collection.update( , , ) Delete • db.collection.remove( , )
  • 25. #MDBLocal db.customers.aggregate([ { $unwind: "$address", }, { $match: {"address.location": "home"} }, { $group: { _id: "$address.city", totalSpend: {$sum: "$annualSpend"}, averageSpend: {$avg: "$annualSpend"}, maximumSpend: {$max: "$annualSpend"}, customers: {$sum: 1} } } ]) Versatile: Complex queries fast to create, optimize, & maintain MongoDB’s aggregation framework has the flexibility you need to get value from your data, but without the complexity and fragility of SQL These “phases” are distinct and easy to understand They can be thought about in order… no nesting.
  • 26. #MDBLocal Versatile: Rich query functionality MongoDB { customer_id : 1, first_name : "Mark", last_name : "Smith", city : "San Francisco", phones: [ { number : "1-212-777-1212", type : "work" }, { number : "1-212-777-1213", type : "cell" }] ……... Expressive Queries • Find anyone with phone # “1-212…” • Check if the person with number “555…” is on the “do not call” list Geospatial • Find the best offer for the customer at geo coordinates of 42nd St. and 6th Ave Text Search • Find all tweets that mention the firm within the last 2 days Aggregation • Count and sort number of customers by city, compute min, max, and average spend Native Binary JSON Support • Add an additional phone number to Mark Smith’s record without rewriting the document • Update just 2 phone numbers out of 10 • Sort on the modified date JOIN ($lookup) • Query for all San Francisco residences, lookup their transactions, and sum the amount by person Graph Queries ($graphLookup) • Query for all people within 3 degrees of separation from Mark
  • 28. #MDBLocal Design Queries to express meaningfulness of data Since we are layering multiple dimensions, leverage queries to express the concepts represented in the data. Example: Customer Information Address Information State in System Metadata for reporting Query – Represent customer and address Query – Get status Query – Pull data for reporting CRUD – Get All
  • 30. #MDBLocal Types of indexes Compound Index Single Field Index Text Index Geospatial Index (lat/lon pairs) Unique Index (ensures uniqueness) TTL Index (Time To Live - automatically delete after elapsed time)
  • 31. #MDBLocal Fully Indexable Fully featured secondary indexes • Primary Index – Every Collection has a primary key index • Compound Index – Index against multiple keys in the document • MultiKey Index – Index into arrays • Wildcard Index – Auto-index all matching fields, sub-documents & arrays • Text Indexes – Support for text searches • GeoSpatial Indexes – 2d & 2dSphere indexes for spatial geometries • Hashed Indexes – Hashed based values for sharding Index Types • TTL Indexes – Single Field indexes, when expired delete the document • Unique Indexes – Ensures value is not duplicated • Partial Indexes – Expression based indexes, allowing indexes on subsets of data • Case Insensitive Indexes • supports text search using case insensitive search • Sparse Indexes – Only index documents which have the given field Index Features
  • 32. #MDBLocal { "_id" : ObjectId("5c1d358bf383fbee028aea0b"), "product_name" : "Blaster Gauntlet", "product_attributes" : { "elements" : [ "Fire" , "Water" ], "price" : 250 ... } }, { "_id" : ObjectId("5c1d358bf383fbee028aea0c"), "product_name" : "Super Suit", "product_attributes" : { "superFlight" : true, "resistance" : [ "Bludgeoning", "Piercing", "Slashing" ] ... }, } Wildcard Indexes Allow more natural data modeling, avoids pre-defining indexes for every access pattern • Polymorphic document structures: Product catalogs, CMS • Ad-hoc queries & data exploration Define a filter that indexes all matching fields, sub-documents, and arrays • Sparse index, omit specific fields • Covered queries & collations • Strongly consistent: updated atomically with base data Index all sub-documents & arrays under Product Attributes
  • 33. #MDBLocal Special place for those who do not Index…
  • 35. #MDBLocal MongoDB Approach Utility of data leveraged with through query and access pattern Data (BSON) Query ( CRUD / Aggregation Pipeline ) Access Pattern ( Indexing ) Utility
  • 36. #MDBLocal One Big Document Use Case A Use Case B Use Case C
  • 37. #MDBLocal Application Specific Domain Customer Orders Status Customer Orders Inventory Focus from Customer point of view OK because logical relationships flow This problematic, because Inventory should be in it’s own logical domain…
  • 38. #MDBLocal Easy: MongoDB Multi-Document ACID Transactions Just like relational transactions • Multi-statement, familiar relational syntax • Easy to add to any application • Multiple documents in 1 or many collections and databases ACID guarantees • Snapshot isolation, all or nothing execution • No performance impact for non-transactional operations
  • 39. #MDBLocal Syntax with client.start_session() as s: s.start_transaction() collection_one.insert_one(doc_one, session=s) collection_two.insert_one(doc_two, session=s) s.commit_transaction() Natural for developers • Idiomatic to the programming language • Familiar to relational developers • Simple
  • 40. #MDBLocal Master and Working Collections Master: Customer Order Use Case Working: Order Read Read/Write Master: Inventory Read • Master collections are stateless • Working collections are stateful • When initiate working document, read as needed from Master • Duplicate only for performance • When Working state changes, write back to Master • Example: inventory consumed • If duplicated data changes in Master, write update to Working file • Example: shipping address • Use Transactions to keep it all straight 1 1 2 2
  • 42. Q&A
  • 43. #MDBlocal Practical Data Modeling for MongoDB: Tutorial https://www.surveymonkey.com/r/6GZ2GQR Every session you rate enters you into a drawing for a $250 Visa gift card, sponsored by