SlideShare a Scribd company logo
MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mindset [MongoDB]
From SQL to NoSQL—
Changing Your Mindset
@Lauren_Schaefer, Developer Advocate, MongoDB
Parks and Recreation, Season 6, Episode 14
MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mindset [MongoDB]
MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mindset [MongoDB]
MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mindset [MongoDB]
Parks and Recreation, Season 6, Episode 14
Lauren Schaefer
Developer Advocate, MongoDB
@Lauren_Schaefer
From SQL to NoSQL—
Changing Your Mindset
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
3. Change your mindset in 3 key ways
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
3. Change your mindset in 3 key ways
MongoDB stores data in documents
MongoDB stores data in documents
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
MongoDB stores data in documents
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
MongoDB stores data in documents
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
MongoDB stores data in documents
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
MongoDB stores data in documents
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
MongoDB stores data in documents
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
MongoDB stores data in documents
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
MongoDB stores data in documents
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
Modeling data in MongoDB vs SQL
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
Modeling data in MongoDB vs SQL
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
ID first_name surname cell city location_x location_y
1 Paul Miller 447557505611 London 45.123 47.232
Users
Modeling data in MongoDB vs SQL
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
ID first_name surname cell city location_x location_y
1 Paul Miller 447557505611 London 45.123 47.232
Users
ID user_id profession
10 1 banking
11 1 finance
12 1 trader
Professions
Modeling data in MongoDB vs SQL
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
ID user_id profession
10 1 banking
11 1 finance
12 1 trader
Professions
ID user_id model year
20 1 Bentley 1973
21 1 Rolls Royce 1965
Cars
ID first_name surname cell city location_x location_y
1 Paul Miller 447557505611 London 45.123 47.232
Users
Modeling data in MongoDB vs SQL
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
ID user_id profession
10 1 banking
11 1 finance
12 1 trader
Professions
ID user_id model year
20 1 Bentley 1973
21 1 Rolls Royce 1965
Cars
ID first_name surname cell city location_x location_y
1 Paul Miller 447557505611 London 45.123 47.232
Users
Collections vs Tables
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
{
first_name: ”Lauren",
surname: ”Schaefer",
cell: ”1235552222",
city: ”Lancaster",
profession: [”software engineer", ”developer advocate"],
}
{
first_name: ”Sydney",
surname: ”Schaefer",
city: ”Lancaster",
school: ”Daisy’s Daycare”
}
ID first_name surname cell city location_x location_y
1 Paul Miller 447557505611 London 45.123 47.232
2 Lauren Schaefer 1235552222 Lancaster NULL NULL
3 Sydney Schaefer NULL Lancaster NULL NULL
UsersUsers
ID first_name surname cell city location_x location_y
1 Paul Miller 447557505611 London 45.123 47.232
2 Lauren Schaefer 1235552222 Lancaster NULL NULL
3 Sydney Schaefer NULL Lancaster NULL NULL
Collections vs Tables
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
{
first_name: ”Lauren",
surname: ”Schaefer",
cell: ”1235552222",
city: ”Lancaster",
profession: [”software engineer", ”developer advocate"],
}
{
first_name: ”Sydney",
surname: ”Schaefer",
city: ”Lancaster",
school: ”Daisy’s Daycare”
}
UsersUsers
Collections vs Tables
ID first_name surname cell city location_x location_y
1 Paul Miller 447557505611 London 45.123 47.232
2 Lauren Schaefer 1235552222 Lancaster NULL NULL
3 Sydney Schaefer NULL Lancaster NULL NULL
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
{
first_name: ”Lauren",
surname: ”Schaefer",
cell: ”1235552222",
city: ”Lancaster",
profession: [”software engineer", ”developer advocate"],
}
{
first_name: ”Sydney",
surname: ”Schaefer",
city: ”Lancaster",
school: ”Daisy’s Daycare”
}
UsersUsers
Schemaless
database
Schemaless
database
Don’t panic!
Use schema validation.
Document Row
{
...
a: “b”
...
}
ID a ...
1 b ...
2 ... ...
3 ... ...
Document Row(s)
{
...
a: “b”
...
}
ID a ...
1 b ...
2 ... ...
3 ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
Field Column
ID a ...
1 b ...
2 c ...
3 ... ...
{
...
a: “b”
...
}
{
...
a: “c”
...
}
Collection Table
{
...
}
... ... ...
... ... ...
... ... ...
... ... ...
{
...
}
{
...
}
Database Database
... ... ...
... ... ...
... ... ...
... ... ...
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
Index Index
{
...
}
{
...
}
{
...
}
{
...
}
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
View View
{
...
}
... ... ...
... ... ...
... ... ...
... ... ...
{
...
}
{
...
}
Embedding Join
{
...
a: “b”,
...
c: {
d: “e”
...
},
...
}
ID a ...
1 b ...
2 ... ...
3 ... ...
... d ...
1 e ...
... ... ...
Database References Join
ID ... ...
1 ... ...
2 ... ...
3 ... ...
... ... ...
1 ... ...
... ... ...
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
$lookup
(Aggregation Pipeline)
Left Outer Join
ID ... ...
1 ... ...
2 ... ...
3 ... ...
... ... ...
1 ... ...
4 ... ...
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
$graphLookup
(Aggregation Pipeline)
Recursive Common Table
Expressions
{
...
}
... ... ...
... ... ...
... ... ...
... ... ...
{
...
}
{
...
}
Multi-Document ACID
Transaction
Multi-Record ACID
Transaction
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
Term mapping summary
x
Row Column Table Database Index Join Join Left Outer
Join
Recursive
Common Table
Expressions
View Transaction
Document Field Collection Database Index Embedding
Database
References
$lookup $graphLookup View Transaction
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
3. Change your mindset in 3 key ways
MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mindset [MongoDB]
MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mindset [MongoDB]
Scale cheaper!
As the size of your database grows, scale horizontally.
SQLMongoDB
Query faster!
Stop doing expensive joins to get your data.
ID a ...
1 b ...
2 ... ...
3 ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
... ... ...
{
...
a: “b”,
...
c: {
d: “e”
...
},
...
}
SQLMongoDB
Pivot easier!
Easily change the shape of your data as your app evolves.
{
a: “b”,
c: “one”,
e: “f”
}
{
a: “b”,
c: 1,
new: “no biggee”
}
ALTER TABLE `mydb`.`letters_table`
DROP COLUMN `e`,
ADD COLUMN `New` VARCHAR(45) NULL AFTER `C`,
CHANGE COLUMN `C` `C` INT NULL DEFAULT NULL ;
Program faster!
Documents map to data structures in most popular languages.
Update Your Profile
Program faster!
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
}
ID first_name surname cell city location_x location_y
1 Paul Miller 447557505611 London 45.123 47.232
Users
ID user_id profession
10 1 banking
11 1 finance
12 1 trader
Professions
Program faster!
import pymongo
from pymongo import MongoClient
# CONNECT TO THE DB
client = MongoClient()
client =
pymongo.MongoClient("mongodb+srv://
username:password@cluster0nsdia.
mongodb.net/test?retryWrites=true")
db = client.fabapp
# THE ID OF THE USER WHOSE PROFILE WE
# WILL BE RETRIEVING AND UPDATING
userId = 1
import mysql.connector
# CONNECT TO THE DB
mydb = mysql.connector.connect(
host="localhost",
user=”username",
passwd=”password",
database=”fabapp”
)
mycursor = mydb.cursor()
# THE ID OF THE USER WHOSE PROFILE WE
# WILL BE RETRIEVING AND UPDATING
userId = 1
Program faster!
# GET THE USER'S PROFILE INFORMATION
## We can pull all of the info from
## the same document since we used
## embedding
user =
db['Users'].find_one({"_id":userId})
# GET THE USER'S PROFILE INFORMATION
### Pull the info from the Users table
### & put it in the user dictionary
sql = "Select * FROM Users WHERE
Users.ID=%s”
values = (userId,)
mycursor.execute(sql, values)
result = mycursor.fetchone()
user = {
"first_name": result[1],
"surname": result[2],
"cell": result[3],
"city": result[4],
"location_x": result[5],
"location_y": result[6]
}
### Pull the info from the Professions
### table & put it in the user dict.
sql = "Select * FROM Professions WHERE
Professions.user_id=%s”
values = (userId,)
mycursor.execute(sql, values)
results = mycursor.fetchall()
professions = []
for result in results:
professions.append(result[2])
user["professions"] = professions
Program faster!
# UPDATE THE USER DICTIONARY BASED ON
# USER INPUT IN THE APP
### We'll update the user dictionary
### manually for simplicity
user = {
"first_name": "NewFirst",
"surname": "NewSurname",
"cell": "123-456-7890",
"city": "NewCity",
"location": [40.762, -73.979],
"professions": ["Manager",
"Engineer"]
}
# UPDATE THE USER DICTIONARY BASED ON
# USER INPUT IN THE APP
### We'll update the user dictionary
### manually for simplicity
user = {
"first_name": "NewFirst",
"surname": "NewSurname",
"cell": "123-456-7890",
"city": "NewCity",
"location_x": 40.762,
"location_y": 73.979,
"professions": ["Manager",
"Engineer"]
}
Program faster!
# UPDATE THE USER'S PROFILE IN THE DB
### Since the user's data is stored in
### a single document, we only have to
### make one update
result = db['Users'].update_one(
{"_id": userId}, {"$set": user})
# UPDATE THE USER'S PROFILE IN THE DB
### First update what is stored in the
### Users table
sql = "UPDATE Users SET first_name=%s,
surname=%s, cell=%s, city=%s,
location_x=%s, location_y=%s
WHERE (ID=%s)"
values = (
user["first_name"],
user["surname"],
user["cell"],
user["city"],
user["location_x"],
user["location_y"],
userId)
mycursor.execute(sql, values)
mydb.commit()
### Delete existing records in
### Professions table and add new ones
sql = "DELETE FROM Professions WHERE
user_id=%s”
values = (userId,)
mycursor.execute(sql, values)
mydb.commit()
if(len(user["professions"]) > 0):
sql = "INSERT INTO Professions
(user_id,profession) VALUES
(%s, %s)”
values = []
for profession in user["professions"]:
values.append((userId, profession))
mycursor.executemany(sql,values)
mydb.commit()
Program faster!
30 lines of code 73 lines of code
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
3. Change your mindset in 3 key ways
MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mindset [MongoDB]
MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mindset [MongoDB]
Embrace document diversity
Embrace document diversity
The Polymorphic Pattern
{
first_name: "Paul",
surname: "Miller",
cell: "447557505611",
city: "London",
location: [45.123,47.232],
profession: ["banking", "finance", "trader"],
cars: [
{
model: "Bentley",
year: 1973
},
{
model: "Rolls Royce",
year: 1965
}
]
}
{
first_name: ”Lauren",
surname: ”Schaefer",
cell: ”1235552222",
city: ”Lancaster",
profession: [”software engineer", ”developer advocate"],
}
{
first_name: ”Sydney",
surname: ”Schaefer",
city: ”Lancaster",
school: ”Daisy’s Daycare”
}
Embrace document diversity
The Outlier Pattern
{
_id: ”Lauren_Schaefer",
displayName: ”Lauren Schaefer",
numFollowers: 1310
followers: [
“naomi_pen”,
“kenwalger”,
“mylynn”
...
]
}
{
_id: ”Nick_Offerman",
displayName: ”Nick Offerman",
numFollowers: 1730332
followers: [
“c_hotaling”,
“IAmJerdog”,
“ChloeCondon”
...
],
has_extras: true
}
{
_id: ”Nick_Offerman_1",
twitter_id: “Nick_Offerman”,
is_overflow: true,
followers: [
“StephenAtHome”,
“TheEllenShow”,
“hulu”
...
]
}
Data that is accessed together should
be stored together
Data that is accessed together should
be stored together
0
20000
40000
60000
80000
100000
120000
1985 2017
Storage vs Developer Costs
Storage Cost per GB Developer Salary
Data that is accessed together should
be stored together
Don’t normalize your data for the sake of normalizing it.
{
a: “b”,
c: {
d: “e”
...
},
f: [“g”, “h”, “i”],
j: [
{
k: “l”
},
{
m: “n”
}
]
}
Data that is accessed together should
be stored together
Tread carefully with transactions
Relying on transactions is a bad design smell.
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
{
...
}
Make the leap from SQL to MongoDB
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
x
Row Column Table Database Index Join Join Left Outer
Join
Recursive
Common Table
Expressions
View Transaction
Document Field Collection Database Index Embedding
Database
References
$lookup $graphLookup View Transaction
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
1. Scale cheaper
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
1. Scale cheaper
2. Program faster
# GET THE USER'S PROFILE INFORMATION
## We can pull all of the info from
## the same document since we used
## embedding
user =
db['Users'].find_one({"_id":userId})
# GET THE USER'S PROFILE INFORMATION
### Pull the info from the Users table ### &
put it in the user dictionary
sql = "Select * FROM Users WHERE
Users.ID=%s”
values = (userId,)
mycursor.execute(sql, values)
result = mycursor.fetchone()
user = {
"first_name": result[1],
"surname": result[2],
"cell": result[3],
"city": result[4],
"location_x": result[5],
"location_y": result[6]
}
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
1. Scale cheaper
2. Program faster
3. Query faster
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
1. Scale cheaper
2. Program faster
3. Query faster
4. Pivot easier
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
3. Change your mindset in 3 key ways
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
3. Change your mindset in 3 key ways
1. Embrace document diversity
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
3. Change your mindset in 3 key ways
1. Embrace document diversity
2. Data that is accessed together should be stored together
Make the leap from SQL to MongoDB
1. Map terms & concepts from SQL to MongoDB
2. Discover the 4 humongous advantages of MongoDB
3. Change your mindset in 3 key ways
1. Embrace document diversity
2. Data that is accessed together should be stored together
3. Tread carefully with transactions
Don’t be Ron Swanson
(in this particular case)
Change your mindset &
get the full value of MongoDB
Don’t be Ron Swanson
Additional resources on data modeling
patterns
• Advanced Schema Design Patterns (webinar)
• Building with Patterns: A Summary (blog series)
• M320: Data Modeling (MongoDB University Course – brand new!)
Additional resources
• The MongoDB Docs
• JSON Schema Validation – Locking down your model the smart way
• JSON Schema Validation - Checking Your Arrays
• M121: The MongoDB Aggregation Framework
Don’t be Ron Swanson
(in this particular case)
Change your mindset and get the
full value of MongoDB
Change your mindset &
get the full value of MongoDB
Get the slides on my Twitter page:
@Lauren_Schaefer
Thank You!
MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mindset [MongoDB]

More Related Content

Similar to MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mindset [MongoDB] (20)

PDF
MongoDB: Back to Basics
Lauren Hayward Schaefer
 
PDF
Jumpstart! Building Your First MongoDB App Using Atlas & Stitch
Lauren Hayward Schaefer
 
PPTX
MongoDB Knowledge share
Mr Kyaing
 
KEY
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
Daniel Cousineau
 
PDF
Which Questions We Should Have
Oracle Korea
 
KEY
Modeling Data in MongoDB
lehresman
 
PPTX
Jumpstart: Introduction to Schema Design
MongoDB
 
PDF
MongoDB Atlas Workshop - Singapore
Ashnikbiz
 
PPTX
introtomongodb
saikiran
 
PPTX
MongoDB Evenings Minneapolis: MongoDB is Cool But When Should I Use It?
MongoDB
 
PDF
MongoDB Basics
Sarang Shravagi
 
PPTX
The Right (and Wrong) Use Cases for MongoDB
MongoDB
 
ODP
MongoDB Distilled
b0ris_1
 
PPTX
lecture_34e.pptx
janibashashaik25
 
PDF
Best Practices for Migrating RDBMS to MongoDB
Sheeri Cabral
 
PDF
Querying Mongo Without Programming Using Funql
MongoDB
 
PPTX
MongoDB Evenings DC: MongoDB - The New Default Database for Giant Ideas
MongoDB
 
PPTX
Introduction to MongoDB at IGDTUW
Ankur Raina
 
PDF
MongoDB FabLab León
Juan Antonio Roy Couto
 
PPTX
Migrating from SQL to MongoDB
MongoDB
 
MongoDB: Back to Basics
Lauren Hayward Schaefer
 
Jumpstart! Building Your First MongoDB App Using Atlas & Stitch
Lauren Hayward Schaefer
 
MongoDB Knowledge share
Mr Kyaing
 
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
Daniel Cousineau
 
Which Questions We Should Have
Oracle Korea
 
Modeling Data in MongoDB
lehresman
 
Jumpstart: Introduction to Schema Design
MongoDB
 
MongoDB Atlas Workshop - Singapore
Ashnikbiz
 
introtomongodb
saikiran
 
MongoDB Evenings Minneapolis: MongoDB is Cool But When Should I Use It?
MongoDB
 
MongoDB Basics
Sarang Shravagi
 
The Right (and Wrong) Use Cases for MongoDB
MongoDB
 
MongoDB Distilled
b0ris_1
 
lecture_34e.pptx
janibashashaik25
 
Best Practices for Migrating RDBMS to MongoDB
Sheeri Cabral
 
Querying Mongo Without Programming Using Funql
MongoDB
 
MongoDB Evenings DC: MongoDB - The New Default Database for Giant Ideas
MongoDB
 
Introduction to MongoDB at IGDTUW
Ankur Raina
 
MongoDB FabLab León
Juan Antonio Roy Couto
 
Migrating from SQL to MongoDB
MongoDB
 

More from MongoDB (20)

PDF
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
PDF
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
PDF
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
PDF
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB
 
PDF
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB
 
PDF
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
PDF
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Powering the new age data demands [Infosys]
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Using Client Side Encryption in MongoDB 4.2
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
PDF
MongoDB .local San Francisco 2020: A Complete Methodology of Data Modeling fo...
MongoDB
 
PDF
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
PDF
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
PDF
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB
 
PDF
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
PDF
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
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
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
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
 
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
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
MongoDB .local San Francisco 2020: Tips and Tricks++ for Querying and Indexin...
MongoDB
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
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
 
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
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
MongoDB .local Paris 2020: Les bonnes pratiques pour sécuriser MongoDB
MongoDB
 
Ad

Recently uploaded (20)

PPTX
Wondershare Filmora Crack Free Download 2025
josanj305
 
PDF
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
PDF
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
PDF
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
PDF
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
PDF
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
PPTX
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
PDF
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
PDF
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
PDF
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
PDF
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
PDF
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
PDF
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
PDF
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
PDF
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
PDF
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
PDF
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
PPTX
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
PPTX
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
PDF
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Wondershare Filmora Crack Free Download 2025
josanj305
 
DoS Attack vs DDoS Attack_ The Silent Wars of the Internet.pdf
CyberPro Magazine
 
How to Visualize the ​Spatio-Temporal Data Using CesiumJS​
SANGHEE SHIN
 
Hyderabad MuleSoft In-Person Meetup (June 21, 2025) Slides
Ravi Tamada
 
“A Re-imagination of Embedded Vision System Design,” a Presentation from Imag...
Edge AI and Vision Alliance
 
Quantum Threats Are Closer Than You Think – Act Now to Stay Secure
WSO2
 
Enabling the Digital Artisan – keynote at ICOCI 2025
Alan Dix
 
Enhancing Environmental Monitoring with Real-Time Data Integration: Leveragin...
Safe Software
 
Understanding AI Optimization AIO, LLMO, and GEO
CoDigital
 
ArcGIS Utility Network Migration - The Hunter Water Story
Safe Software
 
TrustArc Webinar - Navigating APAC Data Privacy Laws: Compliance & Challenges
TrustArc
 
🚀 Let’s Build Our First Slack Workflow! 🔧.pdf
SanjeetMishra29
 
Hello I'm "AI" Your New _________________
Dr. Tathagat Varma
 
Proactive Server and System Monitoring with FME: Using HTTP and System Caller...
Safe Software
 
Understanding The True Cost of DynamoDB Webinar
ScyllaDB
 
Bitkom eIDAS Summit | European Business Wallet: Use Cases, Macroeconomics, an...
Carsten Stoecker
 
Darley - FIRST Copenhagen Lightning Talk (2025-06-26) Epochalypse 2038 - Time...
treyka
 
Paycifi - Programmable Trust_Breakfast_PPTXT
FinTech Belgium
 
Reimaginando la Ciberdefensa: De Copilots a Redes de Agentes
Cristian Garcia G.
 
Java 25 and Beyond - A Roadmap of Innovations
Ana-Maria Mihalceanu
 
Ad

MongoDB .local Houston 2019: Jumpstart: From SQL to NoSQL -- Changing Your Mindset [MongoDB]

  • 2. From SQL to NoSQL— Changing Your Mindset @Lauren_Schaefer, Developer Advocate, MongoDB
  • 3. Parks and Recreation, Season 6, Episode 14
  • 7. Parks and Recreation, Season 6, Episode 14
  • 8. Lauren Schaefer Developer Advocate, MongoDB @Lauren_Schaefer
  • 9. From SQL to NoSQL— Changing Your Mindset
  • 10. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB 3. Change your mindset in 3 key ways
  • 11. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB 3. Change your mindset in 3 key ways
  • 12. MongoDB stores data in documents
  • 13. MongoDB stores data in documents { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] }
  • 14. MongoDB stores data in documents { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] }
  • 15. MongoDB stores data in documents { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] }
  • 16. MongoDB stores data in documents { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] }
  • 17. MongoDB stores data in documents { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] }
  • 18. MongoDB stores data in documents { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] }
  • 19. MongoDB stores data in documents { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] }
  • 20. MongoDB stores data in documents { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] }
  • 21. Modeling data in MongoDB vs SQL { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] }
  • 22. Modeling data in MongoDB vs SQL { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] } ID first_name surname cell city location_x location_y 1 Paul Miller 447557505611 London 45.123 47.232 Users
  • 23. Modeling data in MongoDB vs SQL { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] } ID first_name surname cell city location_x location_y 1 Paul Miller 447557505611 London 45.123 47.232 Users ID user_id profession 10 1 banking 11 1 finance 12 1 trader Professions
  • 24. Modeling data in MongoDB vs SQL { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] } ID user_id profession 10 1 banking 11 1 finance 12 1 trader Professions ID user_id model year 20 1 Bentley 1973 21 1 Rolls Royce 1965 Cars ID first_name surname cell city location_x location_y 1 Paul Miller 447557505611 London 45.123 47.232 Users
  • 25. Modeling data in MongoDB vs SQL { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] } ID user_id profession 10 1 banking 11 1 finance 12 1 trader Professions ID user_id model year 20 1 Bentley 1973 21 1 Rolls Royce 1965 Cars ID first_name surname cell city location_x location_y 1 Paul Miller 447557505611 London 45.123 47.232 Users
  • 26. Collections vs Tables { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] } { first_name: ”Lauren", surname: ”Schaefer", cell: ”1235552222", city: ”Lancaster", profession: [”software engineer", ”developer advocate"], } { first_name: ”Sydney", surname: ”Schaefer", city: ”Lancaster", school: ”Daisy’s Daycare” } ID first_name surname cell city location_x location_y 1 Paul Miller 447557505611 London 45.123 47.232 2 Lauren Schaefer 1235552222 Lancaster NULL NULL 3 Sydney Schaefer NULL Lancaster NULL NULL UsersUsers
  • 27. ID first_name surname cell city location_x location_y 1 Paul Miller 447557505611 London 45.123 47.232 2 Lauren Schaefer 1235552222 Lancaster NULL NULL 3 Sydney Schaefer NULL Lancaster NULL NULL Collections vs Tables { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] } { first_name: ”Lauren", surname: ”Schaefer", cell: ”1235552222", city: ”Lancaster", profession: [”software engineer", ”developer advocate"], } { first_name: ”Sydney", surname: ”Schaefer", city: ”Lancaster", school: ”Daisy’s Daycare” } UsersUsers
  • 28. Collections vs Tables ID first_name surname cell city location_x location_y 1 Paul Miller 447557505611 London 45.123 47.232 2 Lauren Schaefer 1235552222 Lancaster NULL NULL 3 Sydney Schaefer NULL Lancaster NULL NULL { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] } { first_name: ”Lauren", surname: ”Schaefer", cell: ”1235552222", city: ”Lancaster", profession: [”software engineer", ”developer advocate"], } { first_name: ”Sydney", surname: ”Schaefer", city: ”Lancaster", school: ”Daisy’s Daycare” } UsersUsers
  • 31. Document Row { ... a: “b” ... } ID a ... 1 b ... 2 ... ... 3 ... ...
  • 32. Document Row(s) { ... a: “b” ... } ID a ... 1 b ... 2 ... ... 3 ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
  • 33. Field Column ID a ... 1 b ... 2 c ... 3 ... ... { ... a: “b” ... } { ... a: “c” ... }
  • 34. Collection Table { ... } ... ... ... ... ... ... ... ... ... ... ... ... { ... } { ... }
  • 35. Database Database ... ... ... ... ... ... ... ... ... ... ... ... { ... } { ... } { ... } { ... } { ... } { ... } { ... } ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
  • 36. Index Index { ... } { ... } { ... } { ... } ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
  • 37. View View { ... } ... ... ... ... ... ... ... ... ... ... ... ... { ... } { ... }
  • 38. Embedding Join { ... a: “b”, ... c: { d: “e” ... }, ... } ID a ... 1 b ... 2 ... ... 3 ... ... ... d ... 1 e ... ... ... ...
  • 39. Database References Join ID ... ... 1 ... ... 2 ... ... 3 ... ... ... ... ... 1 ... ... ... ... ... { ... } { ... } { ... } { ... } { ... } { ... } { ... }
  • 40. $lookup (Aggregation Pipeline) Left Outer Join ID ... ... 1 ... ... 2 ... ... 3 ... ... ... ... ... 1 ... ... 4 ... ... { ... } { ... } { ... } { ... } { ... } { ... } { ... }
  • 41. $graphLookup (Aggregation Pipeline) Recursive Common Table Expressions { ... } ... ... ... ... ... ... ... ... ... ... ... ... { ... } { ... }
  • 42. Multi-Document ACID Transaction Multi-Record ACID Transaction { ... } { ... } { ... } { ... } { ... } { ... } { ... } ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...
  • 43. Term mapping summary x Row Column Table Database Index Join Join Left Outer Join Recursive Common Table Expressions View Transaction Document Field Collection Database Index Embedding Database References $lookup $graphLookup View Transaction
  • 44. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB 3. Change your mindset in 3 key ways
  • 47. Scale cheaper! As the size of your database grows, scale horizontally.
  • 48. SQLMongoDB Query faster! Stop doing expensive joins to get your data. ID a ... 1 b ... 2 ... ... 3 ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... { ... a: “b”, ... c: { d: “e” ... }, ... }
  • 49. SQLMongoDB Pivot easier! Easily change the shape of your data as your app evolves. { a: “b”, c: “one”, e: “f” } { a: “b”, c: 1, new: “no biggee” } ALTER TABLE `mydb`.`letters_table` DROP COLUMN `e`, ADD COLUMN `New` VARCHAR(45) NULL AFTER `C`, CHANGE COLUMN `C` `C` INT NULL DEFAULT NULL ;
  • 50. Program faster! Documents map to data structures in most popular languages. Update Your Profile
  • 51. Program faster! { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], } ID first_name surname cell city location_x location_y 1 Paul Miller 447557505611 London 45.123 47.232 Users ID user_id profession 10 1 banking 11 1 finance 12 1 trader Professions
  • 52. Program faster! import pymongo from pymongo import MongoClient # CONNECT TO THE DB client = MongoClient() client = pymongo.MongoClient("mongodb+srv:// username:password@cluster0nsdia. mongodb.net/test?retryWrites=true") db = client.fabapp # THE ID OF THE USER WHOSE PROFILE WE # WILL BE RETRIEVING AND UPDATING userId = 1 import mysql.connector # CONNECT TO THE DB mydb = mysql.connector.connect( host="localhost", user=”username", passwd=”password", database=”fabapp” ) mycursor = mydb.cursor() # THE ID OF THE USER WHOSE PROFILE WE # WILL BE RETRIEVING AND UPDATING userId = 1
  • 53. Program faster! # GET THE USER'S PROFILE INFORMATION ## We can pull all of the info from ## the same document since we used ## embedding user = db['Users'].find_one({"_id":userId}) # GET THE USER'S PROFILE INFORMATION ### Pull the info from the Users table ### & put it in the user dictionary sql = "Select * FROM Users WHERE Users.ID=%s” values = (userId,) mycursor.execute(sql, values) result = mycursor.fetchone() user = { "first_name": result[1], "surname": result[2], "cell": result[3], "city": result[4], "location_x": result[5], "location_y": result[6] } ### Pull the info from the Professions ### table & put it in the user dict. sql = "Select * FROM Professions WHERE Professions.user_id=%s” values = (userId,) mycursor.execute(sql, values) results = mycursor.fetchall() professions = [] for result in results: professions.append(result[2]) user["professions"] = professions
  • 54. Program faster! # UPDATE THE USER DICTIONARY BASED ON # USER INPUT IN THE APP ### We'll update the user dictionary ### manually for simplicity user = { "first_name": "NewFirst", "surname": "NewSurname", "cell": "123-456-7890", "city": "NewCity", "location": [40.762, -73.979], "professions": ["Manager", "Engineer"] } # UPDATE THE USER DICTIONARY BASED ON # USER INPUT IN THE APP ### We'll update the user dictionary ### manually for simplicity user = { "first_name": "NewFirst", "surname": "NewSurname", "cell": "123-456-7890", "city": "NewCity", "location_x": 40.762, "location_y": 73.979, "professions": ["Manager", "Engineer"] }
  • 55. Program faster! # UPDATE THE USER'S PROFILE IN THE DB ### Since the user's data is stored in ### a single document, we only have to ### make one update result = db['Users'].update_one( {"_id": userId}, {"$set": user}) # UPDATE THE USER'S PROFILE IN THE DB ### First update what is stored in the ### Users table sql = "UPDATE Users SET first_name=%s, surname=%s, cell=%s, city=%s, location_x=%s, location_y=%s WHERE (ID=%s)" values = ( user["first_name"], user["surname"], user["cell"], user["city"], user["location_x"], user["location_y"], userId) mycursor.execute(sql, values) mydb.commit() ### Delete existing records in ### Professions table and add new ones sql = "DELETE FROM Professions WHERE user_id=%s” values = (userId,) mycursor.execute(sql, values) mydb.commit() if(len(user["professions"]) > 0): sql = "INSERT INTO Professions (user_id,profession) VALUES (%s, %s)” values = [] for profession in user["professions"]: values.append((userId, profession)) mycursor.executemany(sql,values) mydb.commit()
  • 56. Program faster! 30 lines of code 73 lines of code
  • 57. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB 3. Change your mindset in 3 key ways
  • 61. Embrace document diversity The Polymorphic Pattern { first_name: "Paul", surname: "Miller", cell: "447557505611", city: "London", location: [45.123,47.232], profession: ["banking", "finance", "trader"], cars: [ { model: "Bentley", year: 1973 }, { model: "Rolls Royce", year: 1965 } ] } { first_name: ”Lauren", surname: ”Schaefer", cell: ”1235552222", city: ”Lancaster", profession: [”software engineer", ”developer advocate"], } { first_name: ”Sydney", surname: ”Schaefer", city: ”Lancaster", school: ”Daisy’s Daycare” }
  • 62. Embrace document diversity The Outlier Pattern { _id: ”Lauren_Schaefer", displayName: ”Lauren Schaefer", numFollowers: 1310 followers: [ “naomi_pen”, “kenwalger”, “mylynn” ... ] } { _id: ”Nick_Offerman", displayName: ”Nick Offerman", numFollowers: 1730332 followers: [ “c_hotaling”, “IAmJerdog”, “ChloeCondon” ... ], has_extras: true } { _id: ”Nick_Offerman_1", twitter_id: “Nick_Offerman”, is_overflow: true, followers: [ “StephenAtHome”, “TheEllenShow”, “hulu” ... ] }
  • 63. Data that is accessed together should be stored together
  • 64. Data that is accessed together should be stored together
  • 65. 0 20000 40000 60000 80000 100000 120000 1985 2017 Storage vs Developer Costs Storage Cost per GB Developer Salary Data that is accessed together should be stored together
  • 66. Don’t normalize your data for the sake of normalizing it. { a: “b”, c: { d: “e” ... }, f: [“g”, “h”, “i”], j: [ { k: “l” }, { m: “n” } ] } Data that is accessed together should be stored together
  • 67. Tread carefully with transactions Relying on transactions is a bad design smell. { ... } { ... } { ... } { ... } { ... } { ... } { ... }
  • 68. Make the leap from SQL to MongoDB
  • 69. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB x Row Column Table Database Index Join Join Left Outer Join Recursive Common Table Expressions View Transaction Document Field Collection Database Index Embedding Database References $lookup $graphLookup View Transaction
  • 70. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB
  • 71. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB 1. Scale cheaper
  • 72. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB 1. Scale cheaper 2. Program faster # GET THE USER'S PROFILE INFORMATION ## We can pull all of the info from ## the same document since we used ## embedding user = db['Users'].find_one({"_id":userId}) # GET THE USER'S PROFILE INFORMATION ### Pull the info from the Users table ### & put it in the user dictionary sql = "Select * FROM Users WHERE Users.ID=%s” values = (userId,) mycursor.execute(sql, values) result = mycursor.fetchone() user = { "first_name": result[1], "surname": result[2], "cell": result[3], "city": result[4], "location_x": result[5], "location_y": result[6] }
  • 73. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB 1. Scale cheaper 2. Program faster 3. Query faster
  • 74. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB 1. Scale cheaper 2. Program faster 3. Query faster 4. Pivot easier
  • 75. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB 3. Change your mindset in 3 key ways
  • 76. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB 3. Change your mindset in 3 key ways 1. Embrace document diversity
  • 77. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB 3. Change your mindset in 3 key ways 1. Embrace document diversity 2. Data that is accessed together should be stored together
  • 78. Make the leap from SQL to MongoDB 1. Map terms & concepts from SQL to MongoDB 2. Discover the 4 humongous advantages of MongoDB 3. Change your mindset in 3 key ways 1. Embrace document diversity 2. Data that is accessed together should be stored together 3. Tread carefully with transactions
  • 79. Don’t be Ron Swanson (in this particular case)
  • 80. Change your mindset & get the full value of MongoDB Don’t be Ron Swanson
  • 81. Additional resources on data modeling patterns • Advanced Schema Design Patterns (webinar) • Building with Patterns: A Summary (blog series) • M320: Data Modeling (MongoDB University Course – brand new!)
  • 82. Additional resources • The MongoDB Docs • JSON Schema Validation – Locking down your model the smart way • JSON Schema Validation - Checking Your Arrays • M121: The MongoDB Aggregation Framework
  • 83. Don’t be Ron Swanson (in this particular case) Change your mindset and get the full value of MongoDB Change your mindset & get the full value of MongoDB Get the slides on my Twitter page: @Lauren_Schaefer