MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business...
-
Upload
mongodb -
Category
Technology
-
view
929 -
download
0
Transcript of MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business...
![Page 1: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/1.jpg)
From Story to DocumentAPPLYING MONGO ORIENTED THINKING TO BUSINESS REQUIREMENTS
NURI HALPERIN | MONGODB DAYS SILICON VALLEY 2015
![Page 2: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/2.jpg)
Why are we here?
![Page 3: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/3.jpg)
MongoDB SQL
Square pegs, round holes
Experience
Habits
Document
![Page 4: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/4.jpg)
From Tables to Documents
Document
![Page 5: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/5.jpg)
A team story
![Page 6: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/6.jpg)
Good News Everyone!
![Page 7: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/7.jpg)
"Maker Space"
![Page 8: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/8.jpg)
"Victory!"
![Page 9: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/9.jpg)
Let's plan this!
![Page 10: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/10.jpg)
Tables!Constraints!
Normalization!
![Page 11: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/11.jpg)
Person
id UUID
first_name nvarchar(32)
last_name nvarchar(32)
![Page 12: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/12.jpg)
Makers are People!
![Page 13: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/13.jpg)
Person
id UUID
first_name nvarchar(32)
last_name nvarchar(32)
Maker
person_id UUID
status_id Int (not null)
Maker Status
id int
status varchar(16)
![Page 14: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/14.jpg)
Tool
id UUID
name nvarchar(32)
![Page 15: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/15.jpg)
Tool
id UUID
name nvarchar(32)
tool_type_id int
Tool Type
id int
name vharchar
"hand" | "power"
![Page 16: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/16.jpg)
Is everything a tool?
![Page 17: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/17.jpg)
Tool
asset_id UUID
tool_type_id int
Tool Type
id int
name vharchar
is_certifiable bit (not null)
Asset
id UUID
name nvarchar(32)
is_stationary bit
![Page 18: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/18.jpg)
Certification
id UUID
tool_type_id int
date datetime
Maker Certification
member_id UUID
certification_id UUID
date datetime
Person
id UUID
first_name nvarchar(32)
last_name nvarchar(32)
Tool Type
id int
name vharchar
is_certifiable bit (not null)
![Page 19: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/19.jpg)
Tool
asset_id UUID
tool_type_id int
Tool Type
id int
name vharchar
Asset
id UUID
name nvarchar(32)
is_stationary bit
Certificationperson_id UUIDtool_type_id UUIDname varchar(16)
Member Certification
member_id UUIDcertification_id UUIDdate datetime
Member Tool Log
asset_id UUID
type_id int
Person
id UUID
first_name nvarchar(32)
last_name nvarchar(32)
Maker
person_id UUID
status_id Int (not null)
Maker Status
id int
status varchar(16)
![Page 20: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/20.jpg)
Must. Not. Overthink.
![Page 21: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/21.jpg)
Maker gets certified
Borrow & return tool
Report tool usage
![Page 22: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/22.jpg)
Thinking Document
Key interactions drivesdocument design.
![Page 23: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/23.jpg)
Tool
asset_id UUID
type_id int
Tool Type
id int
name vharchar
Asset
id UUID
name nvarchar(32)
is_stationary bit
Certificationperson_id UUIDasset_id UUIDname varchar(16)
Member Certification
member_id UUIDcertification_id UUID
Member Tool Logasset_id UUIDtype_id int
date datetime
Person
id UUID
first_name nvarchar(32)
last_name nvarchar(32)
Maker
person_id UUID
status_id Int (not null)
Maker Status
id int
status varchar(16)
We can do anything!
![Page 24: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/24.jpg)
Generic Purpose-Built
Speed
Efficiency
Scale
Agility
Complexity
Performance
Cost
![Page 25: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/25.jpg)
{_id: ObjectId('…'),name: 'Martha',
}
"Person"
![Page 26: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/26.jpg)
{_id: ObjectId('…'),name: 'Martha',status: 'paid'
}
"Person"
"Maker"
![Page 27: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/27.jpg)
{_id: ObjectId('…'),name: 'Martha',status: 'paid',certified: [{t:'cnc', d:'2015-11-
26'}],}
Get Certified
![Page 28: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/28.jpg)
{_id: ObjectId('…'),name: 'Martha',status: 'paid',certified: [{t:'cnc', d:'2015-11-
26'}],}
db.maker.update({name: 'Martha', 'certified.t':
{$ne:'cnc'}},{ $push:
{certified: {t:'cnc', d: ISODate()} }
}
![Page 29: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/29.jpg)
{_id: ObjectId('…'),name: 'Martha',status: 'paid',certified: [{t:'cnc', d:'2015-11-
26'}],}
Certification
id UUID
person_id UUID
tool_type_id int
date datetime
Maker Certification
member_id UUID
certification_id UUID
Person
id UUID
first_name nvarchar(32)
last_name nvarchar(32)
![Page 30: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/30.jpg)
Thinking Document
Data that works together lives together.
![Page 31: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/31.jpg)
Tables!Constraints!
Normalization!
![Page 32: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/32.jpg)
if ( tool.type != 'hand') {alert('Certification
Required');}
{ _id: 1, name: 'knife', type: 'hand'}{ _id: 2, name: 'drill', type: 'power'}{ _id: 3, name: 'lathe', type: 'stationary'}
![Page 33: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/33.jpg)
if ( tool.type != 'hand') {alert('Certification
Required');}
{ _id: 1, name: 'knife', type: 'hand'}{ _id: 2, name: 'drill', type: 'power'}{ _id: 3, name: 'lathe', type: 'stationary'}{ _id: 4, name: 'scope', type: 'instrument'}
Careful!
X
![Page 34: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/34.jpg)
{ _id: 1, name: 'knife', …, req: false}{ _id: 2, name: 'drill', …, req: true}{ _id: 3, name: 'lathe', …, req: true}{ _id: 4, name: 'scope', …, req: true}
There, I fixed it!
if (tool.requiresCertification) {alert('Certification
Required');}
![Page 35: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/35.jpg)
{ _id: 1, name: 'knife', type: 'hand'}{ _id: 2, name: 'drill', type: 'power'}{ _id: 3, name: 'lathe', type: 'stationary'}{ _id: 4, name: 'scope', type: 'instrument'}X
public enum ToolType {HAND, POWER, STATIONARY
};
OOP, Oops!
![Page 36: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/36.jpg)
Extra Field :: TablesDOWN TIME? COORDINATED DEPLOYMENT?
ALTER TABLE [x]
ADD COLUMN [is_certifiable] bit
DEFAULT 0
![Page 37: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/37.jpg)
Extra Field :: MongoDBFLEXIBLE SCHEMA, CODE FIRST
> db.x.insert({ …, is_certifiable: true})
> db.x.update( {_id: 123}, {$set:{is_certifiable: true}})
On the fly!
![Page 38: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/38.jpg)
Thinking Document
Embed immutable data.
![Page 39: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/39.jpg)
{_id: 1, name: 'scope', borrows: [
{ maker_id: 1, dt: ISODate('2015-06-12'), type: 'out'},
{ maker_id: 1, dt: ISODate('2015-07-04'), type: 'in'},
] }
![Page 40: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/40.jpg)
{ _id: 1, name: 'scope', borrows: [
{ maker_id: 1, dt: ISODate('2015-06-12'), type: 'out'},
{ maker_id: 1, dt: ISODate('2015-07-04'), type: 'in'}, ] }
Embed?Ownership?
Work together?
Bound growth?
Lifetime?
![Page 41: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/41.jpg)
{_id: …,maker: { _id: 17, name: 'bob' }tool : { _id: 1, name: 'scope'},date: ISODate('2015-11-26 18:30Z'),action: 'out'
}
Check tool in / out
Ledger
![Page 42: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/42.jpg)
Maker gets certified
Borrow & return tool
Report tool usage?
![Page 43: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/43.jpg)
db.toolLog.aggregate([{$match: {action: 'out', date: {$gte: ISODate('2015-09-01')
}}},{$group: {_id: "$tool.name", count: {$sum: 1}}},{$sort: {count: -1}}
]);
{ "_id" : "hammer", "count" : 2 }{ "_id" : "torch", "count" : 1 }
![Page 44: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/44.jpg)
db.toolLog.aggregate([{$match: {action: 'out', date: {$gte: ISODate('2015-09-01') }}},
{$group: {_id: "$maker.name", count: {$sum: 1}}},{$sort: {count: -1}}
]);
{ "_id" : "bob", "count" : 2 }{ "_id" : "kim", "count" : 1 }
![Page 45: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/45.jpg)
{ "maker" : "kim", "has" : "hammer", "since" : ISODate("2015-10-03…"), "days" : 31
}
{ "maker" : "bob", "has" : "torch", "since" : ISODate("2015-09-03…"), "days" : 61
}
"Audit Report"
![Page 46: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/46.jpg)
db.toolLog.aggregate([{$sort: {date: -1}},{$group: {
_id: "$tool", action: {$first: "$action"}, at: {$first: "$date"}, by: {$first: "$maker"} }
},{$match: {action: "out"}},{$project: {
_id: 0,"maker": "$by.name", "has": "$_id.name",since: "$at",days: {$divide:[{$subtract: [{$literal: ISODate()}, "$at"]},
1000*60*60*24]}}}
]);
"Audit Report"
![Page 47: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/47.jpg)
{_id: …,maker: { _id: 17, name: 'bob' }tool : { _id: 123, name: 'hammer'},date: ISODate('2015-11-26 18:30Z'),action: 'check-out'
}
db.toolLog.createindex({date: 1,
"tool.name": 1})
![Page 48: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/48.jpg)
Thinking Document
Let the engine work for you
![Page 49: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/49.jpg)
Toolasset_id UUIDtype_id int
Tool Typeid intname vharchar
Assetid UUIDname nvarchar(32)is_stationary bit
TableLand
Certificationperson_id UUIDasset_id UUIDname varchar(16)
Member Certificationmember_id UUIDcertification_id UUID
Personid UUIDfirst_name nvarchar(32)last_name nvarchar(32)
Maker
person_id UUID
status_id Int (not null)
Maker Statusid intstatus varchar(16)
Member Tool Logasset_id UUIDtype_id int
date datetime
![Page 50: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/50.jpg)
maker
tool
toolLog
{_id: 17,name: 'bob',status: 'paid',certified: [
{t:'cnc', d:'2015-11-26'}
],}
{_id: 2,name: 'drill',type: 'power',
}
{_id: 789234,maker: { _id: 17, name:
'bob' }tool : { _id: 2, name:
'drill'},date: ISODate('2015-11-26
18:30Z'),action: 'check-out'
}
![Page 51: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/51.jpg)
Thinking Document
Key interactions drivesdocument design.
![Page 52: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/52.jpg)
Thinking Document
Data that works together lives together.
![Page 53: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/53.jpg)
Thinking Document
Embed immutable data.
![Page 54: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/54.jpg)
Thinking Document
Let the engine work for you
![Page 55: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/55.jpg)
Thinking Document
*Rules enforced by application.
![Page 56: MongoDB Days Silicon Valley: From Story to Document: Applying MongoDB Thinking to Business Requirements](https://reader035.fdocuments.in/reader035/viewer/2022062412/586f6ef51a28ab10258b45bf/html5/thumbnails/56.jpg)
Thank you! Nuri Halperin +N Consulting [email protected] nurih @nurih