SlideShare a Scribd company logo
#MDBlocal
Austin Zellner
Practical Data Modelling
CHICAGO
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
#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
Ad

Recommended

MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
MongoDB .local Toronto 2019: MongoDB Atlas Search Deep Dive
MongoDB .local Toronto 2019: MongoDB Atlas Search Deep Dive
MongoDB
 
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
MongoDB .local Munich 2019: Best Practices for Working with IoT and Time-seri...
MongoDB
 
MongoDB .local Munich 2019: Still Haven't Found What You Are Looking For? Use...
MongoDB .local Munich 2019: Still Haven't Found What You Are Looking For? Use...
MongoDB
 
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 Data
MongoDB
 
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB .local Toronto 2019: Using Change Streams to Keep Up with Your Data
MongoDB
 
[MongoDB.local Bengaluru 2018] Just in Time Validation with JSON Schema
[MongoDB.local Bengaluru 2018] Just in Time Validation with JSON Schema
MongoDB
 
Database Trends for Modern Applications: Why the Database You Choose Matters
Database Trends for Modern Applications: Why the Database You Choose Matters
MongoDB
 
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
MongoDB
 
MongoDB .local Chicago 2019: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local Chicago 2019: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
Joins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation Enhancements
Andrew Morgan
 
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
 
Deciphering Explain Output
Deciphering Explain Output
MongoDB
 
Webinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and Java
MongoDB
 
MongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and Implications
MongoDB
 
Webinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDB
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
 
MongoDB Meetup
MongoDB Meetup
Maxime Beugnet
 
MongoDB Stich Overview
MongoDB Stich Overview
MongoDB
 
N1QL workshop: Indexing & Query turning.
N1QL workshop: Indexing & Query turning.
Keshav Murthy
 
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB
 
High Performance Applications with MongoDB
High Performance Applications with MongoDB
MongoDB
 
MongodB Internals
MongodB Internals
Norberto Leite
 
Python and MongoDB as a Market Data Platform by James Blackburn
Python and MongoDB as a Market Data Platform by James Blackburn
PyData
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
MongoDB
 
User Data Management with MongoDB
User Data Management with MongoDB
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
 
Getting to Insights Faster with the MongoDB Connector for BI
Getting to Insights Faster with the MongoDB Connector for BI
MongoDB
 
Jumpstart: Introduction to MongoDB
Jumpstart: Introduction to MongoDB
MongoDB
 
MongoDB Atlas Workshop - Singapore
MongoDB Atlas Workshop - Singapore
Ashnikbiz
 

More Related Content

What's hot (20)

Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
MongoDB
 
MongoDB .local Chicago 2019: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local Chicago 2019: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
Joins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation Enhancements
Andrew Morgan
 
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
 
Deciphering Explain Output
Deciphering Explain Output
MongoDB
 
Webinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and Java
MongoDB
 
MongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and Implications
MongoDB
 
Webinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDB
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
 
MongoDB Meetup
MongoDB Meetup
Maxime Beugnet
 
MongoDB Stich Overview
MongoDB Stich Overview
MongoDB
 
N1QL workshop: Indexing & Query turning.
N1QL workshop: Indexing & Query turning.
Keshav Murthy
 
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB
 
High Performance Applications with MongoDB
High Performance Applications with MongoDB
MongoDB
 
MongodB Internals
MongodB Internals
Norberto Leite
 
Python and MongoDB as a Market Data Platform by James Blackburn
Python and MongoDB as a Market Data Platform by James Blackburn
PyData
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
MongoDB
 
User Data Management with MongoDB
User Data Management with MongoDB
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
 
Getting to Insights Faster with the MongoDB Connector for BI
Getting to Insights Faster with the MongoDB Connector for BI
MongoDB
 
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
Joins and Other Aggregation Enhancements Coming in MongoDB 3.2
MongoDB
 
MongoDB .local Chicago 2019: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local Chicago 2019: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
Joins and Other MongoDB 3.2 Aggregation Enhancements
Joins and Other MongoDB 3.2 Aggregation Enhancements
Andrew Morgan
 
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
 
Deciphering Explain Output
Deciphering Explain Output
MongoDB
 
Webinar: Building Your First App with MongoDB and Java
Webinar: Building Your First App with MongoDB and Java
MongoDB
 
MongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and Implications
MongoDB
 
Webinar: Transitioning from SQL to MongoDB
Webinar: Transitioning from SQL to MongoDB
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
 
MongoDB Stich Overview
MongoDB Stich Overview
MongoDB
 
N1QL workshop: Indexing & Query turning.
N1QL workshop: Indexing & Query turning.
Keshav Murthy
 
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB
 
High Performance Applications with MongoDB
High Performance Applications with MongoDB
MongoDB
 
Python and MongoDB as a Market Data Platform by James Blackburn
Python and MongoDB as a Market Data Platform by James Blackburn
PyData
 
Back to Basics: My First MongoDB Application
Back to Basics: My First MongoDB Application
MongoDB
 
User Data Management with MongoDB
User Data Management with MongoDB
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
 
Getting to Insights Faster with the MongoDB Connector for BI
Getting to Insights Faster with the MongoDB Connector for BI
MongoDB
 

Similar to MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial (20)

Jumpstart: Introduction to MongoDB
Jumpstart: Introduction to MongoDB
MongoDB
 
MongoDB Atlas Workshop - Singapore
MongoDB Atlas Workshop - Singapore
Ashnikbiz
 
Jumpstart: Introduction to Schema Design
Jumpstart: Introduction to Schema Design
MongoDB
 
[MongoDB.local Bengaluru 2018] Jumpstart: Introduction to Schema Design
[MongoDB.local Bengaluru 2018] Jumpstart: Introduction to Schema Design
MongoDB
 
Jumpstart: Your Introduction To MongoDB
Jumpstart: Your Introduction To MongoDB
MongoDB
 
MongoDB Evenings Minneapolis: MongoDB is Cool But When Should I Use It?
MongoDB Evenings Minneapolis: MongoDB is Cool But When Should I Use It?
MongoDB
 
Which Questions We Should Have
Which Questions We Should Have
Oracle Korea
 
Simplifying & accelerating application development with MongoDB's intelligent...
Simplifying & accelerating application development with MongoDB's intelligent...
Maxime Beugnet
 
Building your First MEAN App
Building your First MEAN App
MongoDB
 
Jumpstart: Building Your First App with MongoDB
Jumpstart: Building Your First App with MongoDB
MongoDB
 
Jumpstart: Introduction to Schema Design
Jumpstart: Introduction to Schema Design
MongoDB
 
Jumpstart! From SQL to NoSQL -- Changing Your Mindset
Jumpstart! From SQL to NoSQL -- Changing Your Mindset
Lauren Hayward Schaefer
 
Introduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUW
Ankur Raina
 
MongoDB Evenings DC: MongoDB - The New Default Database for Giant Ideas
MongoDB Evenings DC: MongoDB - The New Default Database for Giant Ideas
MongoDB
 
Jumpstart: Your Introduction to MongoDB
Jumpstart: Your Introduction to MongoDB
MongoDB
 
Confluent & MongoDB APAC Lunch & Learn
Confluent & MongoDB APAC Lunch & Learn
confluent
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
MongoDB
 
MongoDB .local London 2019: Managing Diverse User Needs with MongoDB and SQL
MongoDB .local London 2019: Managing Diverse User Needs with MongoDB and SQL
MongoDB
 
MongoDB 3.4 webinar
MongoDB 3.4 webinar
Andrew Morgan
 
An Introduction to Mongo DB
An Introduction to Mongo DB
WeAreEsynergy
 
Jumpstart: Introduction to MongoDB
Jumpstart: Introduction to MongoDB
MongoDB
 
MongoDB Atlas Workshop - Singapore
MongoDB Atlas Workshop - Singapore
Ashnikbiz
 
Jumpstart: Introduction to Schema Design
Jumpstart: Introduction to Schema Design
MongoDB
 
[MongoDB.local Bengaluru 2018] Jumpstart: Introduction to Schema Design
[MongoDB.local Bengaluru 2018] Jumpstart: Introduction to Schema Design
MongoDB
 
Jumpstart: Your Introduction To MongoDB
Jumpstart: Your Introduction To MongoDB
MongoDB
 
MongoDB Evenings Minneapolis: MongoDB is Cool But When Should I Use It?
MongoDB Evenings Minneapolis: MongoDB is Cool But When Should I Use It?
MongoDB
 
Which Questions We Should Have
Which Questions We Should Have
Oracle Korea
 
Simplifying & accelerating application development with MongoDB's intelligent...
Simplifying & accelerating application development with MongoDB's intelligent...
Maxime Beugnet
 
Building your First MEAN App
Building your First MEAN App
MongoDB
 
Jumpstart: Building Your First App with MongoDB
Jumpstart: Building Your First App with MongoDB
MongoDB
 
Jumpstart: Introduction to Schema Design
Jumpstart: Introduction to Schema Design
MongoDB
 
Jumpstart! From SQL to NoSQL -- Changing Your Mindset
Jumpstart! From SQL to NoSQL -- Changing Your Mindset
Lauren Hayward Schaefer
 
Introduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUW
Ankur Raina
 
MongoDB Evenings DC: MongoDB - The New Default Database for Giant Ideas
MongoDB Evenings DC: MongoDB - The New Default Database for Giant Ideas
MongoDB
 
Jumpstart: Your Introduction to MongoDB
Jumpstart: Your Introduction to MongoDB
MongoDB
 
Confluent & MongoDB APAC Lunch & Learn
Confluent & MongoDB APAC Lunch & Learn
confluent
 
ETL for Pros: Getting Data Into MongoDB
ETL for Pros: Getting Data Into MongoDB
MongoDB
 
MongoDB .local London 2019: Managing Diverse User Needs with MongoDB and SQL
MongoDB .local London 2019: Managing Diverse User Needs with MongoDB and SQL
MongoDB
 
An Introduction to Mongo DB
An Introduction to Mongo DB
WeAreEsynergy
 
Ad

More from MongoDB (20)

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
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
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
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
 
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.2
MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
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
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
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
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
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
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
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
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
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
 
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
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
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
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
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
 
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.2
MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
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
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
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
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
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
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
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
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
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
 
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
 
Ad

Recently uploaded (20)

vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
vertical-cnc-processing-centers-drillteq-v-200-en.pdf
AmirStern2
 
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc Webinar - 2025 Global Privacy Survey
TrustArc
 
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
Can We Use Rust to Develop Extensions for PostgreSQL? (POSETTE: An Event for ...
NTT DATA Technology & Innovation
 
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik - Passionate Tech Enthusiast
Raman Bhaumik
 
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
Tech-ASan: Two-stage check for Address Sanitizer - Yixuan Cao.pdf
caoyixuan2019
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
War_And_Cyber_3_Years_Of_Struggle_And_Lessons_For_Global_Security.pdf
biswajitbanerjee38
 
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Seminar: Perspectives on Passkeys & Consumer Adoption.pptx
FIDO Alliance
 
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Seminar: Authentication for a Billion Consumers - Amazon.pptx
FIDO Alliance
 
Securing Account Lifecycles in the Age of Deepfakes.pptx
Securing Account Lifecycles in the Age of Deepfakes.pptx
FIDO Alliance
 
AI vs Human Writing: Can You Tell the Difference?
AI vs Human Writing: Can You Tell the Difference?
Shashi Sathyanarayana, Ph.D
 
Murdledescargadarkweb.pdfvolumen1 100 elementary
Murdledescargadarkweb.pdfvolumen1 100 elementary
JorgeSemperteguiMont
 
OWASP Barcelona 2025 Threat Model Library
OWASP Barcelona 2025 Threat Model Library
PetraVukmirovic
 
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Seminar: Targeting Trust: The Future of Identity in the Workforce.pptx
FIDO Alliance
 
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
SAP Modernization Strategies for a Successful S/4HANA Journey.pdf
Precisely
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Mastering AI Workflows with FME - Peak of Data & AI 2025
Mastering AI Workflows with FME - Peak of Data & AI 2025
Safe Software
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 

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

  • 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