SlideShare a Scribd company logo
#MDBlocal
Just in Time Validation with
JSON Schema
#MDBlocal
Shannon Bradshaw
VP of Developer Education,
Snowboarding Enthusiast, Father
MongoDB
@shannonbradshaw
#MDBlocal
$jsonSchema
#MDBlocal
Flexible
Schema
Rigid
Schema
Your App
#MDBlocal
Flexible
Schema
Rigid
Schema
Your App
risk
success!
regulation
policy
politics
#MDBlocal
Flexible
Schema
Rigid
Schema
Your App
risk
success!
regulation
policy
politics
Production
Concerns
#MDBlocal
#MDBlocal
{
_id: 34556,
item: "Flannel T-shirt",
price: NumberDecimal("27.99"),
quantity: NumberInt(1)
color: "green"
}
Simple Schema to Start
#MDBlocal
Document Validation (v3.2)
Use query filters to define schema constraints. E.g.,
db.createCollection("orders", {
validator: {
item: {$type: "string"},
price: {$type: "decimal"},
quantity: {$type: "int"},
color: {$in: ["red", "green", "blue"]}
}
});
(ex1 - ex6)
#MDBlocal
JSON Schema (v3.6)
● JSON Schema Draft 04
● Is becoming an industry standard
● Widely used; lots of community support
(ex5)
#MDBlocal
Flexible
Schema
Rigid
Schema
Our App
#MDBlocal
(ex6 - ex8b)
Let's make our validator a little
more strict
#MDBlocal
Good for Starter Examples
{
_id: 34556,
item: "Flannel T-shirt",
price: NumberDecimal("27.99"),
quantity: NumberLong(1),
color: "green"
}
{
_id: 34556,
total: NumberDecimal("141.00"),
VAT: NumberDecimal("0.20"),
totalWithVAT: NumberDecimal("169.20"),
lineitems: [
{ sku: "MDBTS001",
name: "Flannel T-shirt",
quantity: 10,
unit_price: NumberDecimal("9.00") },
{ sku: "MDBTS002",
quantity: 5,
unit_price: NumberDecimal("10.00")}]
}
More Realistic
#MDBlocal
Good for Starter Examples
{
_id: 34556,
item: "Flannel T-shirt",
price: NumberDecimal("27.99"),
quantity: NumberLong(1),
color: "green"
}
{
_id: 34556,
total: NumberDecimal("141.00"),
VAT: NumberDecimal("0.20"),
totalWithVAT: NumberDecimal("169.20"),
lineitems: [
{ sku: "MDBTS001",
name: "Flannel T-shirt",
quantity: 10,
unit_price: NumberDecimal("9.00") },
{ sku: "MDBTS002",
quantity: 5,
unit_price: NumberDecimal("10.00")}]
}
More Realistic
#MDBlocal
Our New Orders Schema
● Orders must contain a lineitems array of 1 to 10 documents
● Documents embedded in lineitems have fields for:
○ sku (required)
○ name (optional)
○ unit_price (required)
○ quantity (required)
● Value of quantity must be an integer
● (Must also contain fields: total, VAT, totalWithVAT, but we'll get to that.)
#MDBlocal
Let's validate the line item documents
(embedded in an array)
(ex9 - 10b)
#MDBlocal
Now Let's Deal with Totals and VAT
The most recent order we looked at actually contains a few errors:
● The totalWithVAT value should be 141 * 1.20 = 169.2
● The total value should be the sum of each line item sub-total
● I.e., (10 * 9) + (10 * 5) = 140
Can we enforce that totalWithVAT and total are correct using validation?
#MDBlocal
Yes we can!
● MongoDB 3.6 -- more expressive query syntax
● Can express complex business rules in validations
● E.g, compute and compare multiple values at runtime
#MDBlocal
$expr
Check that totalWithVAT == total * (1+VAT):
$expr: {
$eq: [
"$totalWithVAT",
{$multiply: [
"$total",
{$sum: [1, "$VAT"]}
]}
]
}
Let's add this as a validation rule alongside our JSON Schema validation ()
#MDBlocal
Now let's make sure the total is the
sum of the line item subtotals
#MDBlocal
Ensure total equals sum of line items
$expr: {
$eq: [
"$total",
{$sum: {
$map: {
"input": "$lineitems",
"as": "item",
"in": {
"$multiply": [
"$$item.quantity",
"$$item.unit_price"
] } } }} ] }
#MDBlocal
All together now
(ex11 - 14c)
#MDBlocal
Flexible
Schema
Rigid
Schema
Our App
#MDBlocal
Flexible
Schema
Rigid
Schema
risk
success!
regulation
policy
politics
Our App
#MDBlocal
Flexible
Schema
Rigid
Schema
risk
success!
regulation
policy
politics
Our App
Production
Concerns
#MDBlocal
Special thanks to Raphael Londner
#MDBlocal
Learn More
● What's New Guide
● MongoDB Documentation
○ Schema Validation
○ Expressive Query Syntax
● Free MongoDB 3.6 Online Course from MongoDB University

More Related Content

What's hot (20)

PDF
MongoDB Aggregation Framework
Caserta
 
PDF
MongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB
 
PPTX
Aggregation in MongoDB
Kishor Parkhe
 
PDF
Embedding a language into string interpolator
Michael Limansky
 
PDF
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB
 
PPTX
The Aggregation Framework
MongoDB
 
PPTX
The Aggregation Framework
MongoDB
 
KEY
MongoDB Aggregation Framework
Tyler Brock
 
PPTX
Webinar: Exploring the Aggregation Framework
MongoDB
 
PDF
Aggregation Framework MongoDB Days Munich
Norberto Leite
 
PDF
MongoDB .local Bengaluru 2019: Aggregation Pipeline Power++: How MongoDB 4.2 ...
MongoDB
 
PPTX
Agg framework selectgroup feb2015 v2
MongoDB
 
PPTX
Powerful Analysis with the Aggregation Pipeline
MongoDB
 
PPTX
MongoDB World 2016 : Advanced Aggregation
Joe Drumgoole
 
ODP
Aggregation Framework in MongoDB Overview Part-1
Anuj Jain
 
PPTX
MongoDB Aggregation
Amit Ghosh
 
PDF
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB
 
PDF
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
MongoDB
 
PPTX
[MongoDB.local Bengaluru 2018] Tutorial: Pipeline Power - Doing More with Mon...
MongoDB
 
PDF
MongoDB Europe 2016 - Graph Operations with MongoDB
MongoDB
 
MongoDB Aggregation Framework
Caserta
 
MongoDB Europe 2016 - Advanced MongoDB Aggregation Pipelines
MongoDB
 
Aggregation in MongoDB
Kishor Parkhe
 
Embedding a language into string interpolator
Michael Limansky
 
MongoDB Europe 2016 - ETL for Pros – Getting Data Into MongoDB The Right Way
MongoDB
 
The Aggregation Framework
MongoDB
 
The Aggregation Framework
MongoDB
 
MongoDB Aggregation Framework
Tyler Brock
 
Webinar: Exploring the Aggregation Framework
MongoDB
 
Aggregation Framework MongoDB Days Munich
Norberto Leite
 
MongoDB .local Bengaluru 2019: Aggregation Pipeline Power++: How MongoDB 4.2 ...
MongoDB
 
Agg framework selectgroup feb2015 v2
MongoDB
 
Powerful Analysis with the Aggregation Pipeline
MongoDB
 
MongoDB World 2016 : Advanced Aggregation
Joe Drumgoole
 
Aggregation Framework in MongoDB Overview Part-1
Anuj Jain
 
MongoDB Aggregation
Amit Ghosh
 
MongoDB Europe 2016 - Debugging MongoDB Performance
MongoDB
 
MongoDB .local Paris 2020: La puissance du Pipeline d'Agrégation de MongoDB
MongoDB
 
[MongoDB.local Bengaluru 2018] Tutorial: Pipeline Power - Doing More with Mon...
MongoDB
 
MongoDB Europe 2016 - Graph Operations with MongoDB
MongoDB
 

Similar to Data Governance with JSON Schema (15)

PPTX
[MongoDB.local Bengaluru 2018] Just in Time Validation with JSON Schema
MongoDB
 
PDF
MongoDB World 2019: Just-in-time Validation with JSON Schema
MongoDB
 
PPTX
Document Validation in MongoDB 3.2
MongoDB
 
PPTX
Keynote: New in MongoDB: Atlas, Charts, and Stitch
MongoDB
 
PPTX
How to leverage what's new in MongoDB 3.6
Maxime Beugnet
 
PPTX
SH 1 - SES 2 part 2 - Tel Aviv MDBlocal - Eliot Keynote.pptx
MongoDB
 
PPTX
SH 1 - SES 2 part 2 - Tel Aviv MDBlocal - Eliot Keynote.pptx
MongoDB
 
PPTX
Document validation in MongoDB 3.2
Andrew Morgan
 
PDF
MongoDB.pdf
ArthyR3
 
PDF
MongoDB Meetup
Maxime Beugnet
 
PPTX
MongoDB World 2018: Keynote
MongoDB
 
PPTX
Keynote - Speaker: Grigori Melnik
MongoDB
 
PDF
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB
 
PPTX
MongoDB Days UK: Building Apps with the MEAN Stack
MongoDB
 
PPTX
[MongoDB.local Bengaluru 2018] Keynote
MongoDB
 
[MongoDB.local Bengaluru 2018] Just in Time Validation with JSON Schema
MongoDB
 
MongoDB World 2019: Just-in-time Validation with JSON Schema
MongoDB
 
Document Validation in MongoDB 3.2
MongoDB
 
Keynote: New in MongoDB: Atlas, Charts, and Stitch
MongoDB
 
How to leverage what's new in MongoDB 3.6
Maxime Beugnet
 
SH 1 - SES 2 part 2 - Tel Aviv MDBlocal - Eliot Keynote.pptx
MongoDB
 
SH 1 - SES 2 part 2 - Tel Aviv MDBlocal - Eliot Keynote.pptx
MongoDB
 
Document validation in MongoDB 3.2
Andrew Morgan
 
MongoDB.pdf
ArthyR3
 
MongoDB Meetup
Maxime Beugnet
 
MongoDB World 2018: Keynote
MongoDB
 
Keynote - Speaker: Grigori Melnik
MongoDB
 
MongoDB .local Chicago 2019: Practical Data Modeling for MongoDB: Tutorial
MongoDB
 
MongoDB Days UK: Building Apps with the MEAN Stack
MongoDB
 
[MongoDB.local Bengaluru 2018] Keynote
MongoDB
 
Ad

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: From SQL to NoSQL -- Changing Your Mindset
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: 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: From SQL to NoSQL -- Changing Your Mindset
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: 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
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
PPTX
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
PPTX
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
PDF
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
PDF
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
PPTX
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
PDF
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
PPTX
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
DOCX
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
PDF
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
PDF
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
PDF
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
PDF
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
PDF
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
PPT
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
PDF
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
PDF
Staying Human in a Machine- Accelerated World
Catalin Jora
 
PDF
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
DOCX
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
PDF
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 
Q2 FY26 Tableau User Group Leader Quarterly Call
lward7
 
Designing_the_Future_AI_Driven_Product_Experiences_Across_Devices.pptx
presentifyai
 
The Project Compass - GDG on Campus MSIT
dscmsitkol
 
UPDF - AI PDF Editor & Converter Key Features
DealFuel
 
“Computer Vision at Sea: Automated Fish Tracking for Sustainable Fishing,” a ...
Edge AI and Vision Alliance
 
Mastering ODC + Okta Configuration - Chennai OSUG
HathiMaryA
 
Future-Proof or Fall Behind? 10 Tech Trends You Can’t Afford to Ignore in 2025
DIGITALCONFEX
 
New ThousandEyes Product Innovations: Cisco Live June 2025
ThousandEyes
 
Cryptography Quiz: test your knowledge of this important security concept.
Rajni Bhardwaj Grover
 
Go Concurrency Real-World Patterns, Pitfalls, and Playground Battles.pdf
Emily Achieng
 
Peak of Data & AI Encore AI-Enhanced Workflows for the Real World
Safe Software
 
How do you fast track Agentic automation use cases discovery?
DianaGray10
 
Transcript: Book industry state of the nation 2025 - Tech Forum 2025
BookNet Canada
 
UiPath DevConnect 2025: Agentic Automation Community User Group Meeting
DianaGray10
 
Ericsson LTE presentation SEMINAR 2010.ppt
npat3
 
NLJUG Speaker academy 2025 - first session
Bert Jan Schrijver
 
Staying Human in a Machine- Accelerated World
Catalin Jora
 
SIZING YOUR AIR CONDITIONER---A PRACTICAL GUIDE.pdf
Muhammad Rizwan Akram
 
Python coding for beginners !! Start now!#
Rajni Bhardwaj Grover
 
Automating Feature Enrichment and Station Creation in Natural Gas Utility Net...
Safe Software
 

Data Governance with JSON Schema