SlideShare a Scribd company logo
1 of 46
Intro To MongoDB
Buzz Moschetti
Enterprise Architect, MongoDB
buzz.moschetti@mongodb.com
@buzzmoschetti
Who is Talking To You?
• Yes, I use “Buzz” on my business cards
• Former Investment Bank Chief Architect at JPMorganChase
and Bear Stearns
• Over 30 years of designing and building systems
• Big and small
• Super-specialized to broadly useful in any vertical
• “Traditional” to completely disruptive
• Advocate of language leverage and strong factoring
• Inventor of perl DBI/DBD
• Not an award winner for PowerPoint
• Still programming – using emacs, of course
Agenda
• What is MongoDB?
• What are some good use cases?
• How do I use it?
• How do I deploy it?
MongoDB: The Leading NoSQL Database
Document
Data Model
Open-
Source
Fully Featured
High Performance
Scalable
{
name: “John Smith”,
pfxs: [“Dr.”,”Mr.”],
address: “10 3rd St.”,
phones: [
{ number: “555-1212”,
type: “land” },
{ number: “444-1212”,
type: “mobile” }
]
}
5
The best way to run
MongoDB
Automated.
Supported.
Secured.
Features beyond those in the
community edition:
Enterprise-Grade Support
Commercial License
Ops Manager or Cloud Manager Premium
Encrypted & In-Memory Storage Engines
MongoDB Compass
BI Connector (SQL Bridge)
Advanced Security
Platform Certification
On-Demand Training
MongoDB Enterprise Edition
Company Vital Stats
500+ employees 2000+ customers
Over $311 million in funding
Offices in NY & Palo Alto and
across EMEA, and APAC
The Database Landscape
RDBMS MongoDB
Database Database
Table Collection
Index Index
Row Document
Column Field
Join Embedding & Linking & $lookup
Terminology
{
_id: “123”,
title: "MongoDB: The Definitive Guide",
authors: [
{ _id: "kchodorow", name: "Kristina Chodorow“ },
{ _id: "mdirold", name: “Mike Dirolf“ }
],
published_date: ISODate(”2010-09-24”),
pages: 216,
language: "English",
thumbnail: BinData(0,"AREhMQ=="),
publisher: {
name: "O’Reilly Media",
founded: 1980,
locations: ["CA”, ”NY” ]
}
}
The Data Is The Schema
> db.authors.find()
{
_id: ”X12",
name: { first: "Kristina”, last: “Chodorow” },
personalData: {
favoritePets: [ “bird”, “dog” ],
awards: [ {name: “Hugo”, when: 1983}, {name: “SSFX”,
when: 1992} ]
}
}
{
_id: ”Y45",
name: { first: ”Mike”, last: “Dirolf” } ,
personalData: {
dob: ISODate(“1970-04-05”)
}
}
Treat Your Data More Like Objects
// Java: maps
DBObject query = new BasicDBObject(”publisher.founded”, 1980));
Map m = collection.findOne(query);
Date pubDate = (Date)m.get(”published_date”); // java.util.Date
List locs = (List)m.get(”locations”);
// Javascript: objects
m = collection.findOne({”publisher.founded” : 1980});
pubDate = m.published_date; // ISODate
year = pubDate.getUTCFullYear();
# Python: dictionaries
m = coll.find_one({”publisher.founded” : 1980 });
pubDate = m[”pubDate”].year # datetime.datetime
Documents Natively Map to Language
12
Traditional Data Design
• Static, Uniform Scalar Data
• Rectangles
• Low-level, physical representation
13
Document Data Design
• Flexible, Rich Shapes
• Objects
• High-level, business representation
Agenda
• What is MongoDB?
• What are some good use cases?
• How do I use it?
• How do I deploy it?
15
MongoDB 3.0 Set The Stage…
7x-10x Performance, 50%-80% Less Storage
How: WiredTiger Storage Engine
• Same data model, query language, & ops
• 100% backwards compatible API
• Non-disruptive upgrade
• Storage savings driven by native
compression
• Write performance gains driven by
– Document-level concurrency control
– More efficient use of HW threads
• Much better ability to scale vertically
MongoDB 3.0MongoDB 2.6
Performance
16
MongoDB 3.2 :
Efficient Enterprise MongoDB
• Much better ability to scale vertically
+
• Document Validation Rules
• Encryption at rest
• BI Connector (SQL bridge)
• MongoDB Compass
• New Relic & AppDynamics integration
• Backup snapshots on filesystem
• Advanced Full-text languages
• $lookup (“left outer JOIN”)
More
general-purpose
solutions
17
MongoDB Sweet Spot Use Cases
Big Data
Product &
Asset Catalogs Security &
Fraud
Internet of
Things
Database-as-
a- Service
Mobile
Apps
Customer
Data
Management
Single View Social &
Collaboration
Content
Management
Intelligence
Agencies
Top Investment
and Retail Banks
Top Global
Shipping Company
Top Industrial
Equipment
Manufacturer
Top Media
Company
Top Investment
and Retail Banks
Complex Data
Management
Top Investment
and Retail Banks
Embedded /
ISV
Cushman &
Wakefield
Agenda
• What is MongoDB?
• What are some good use cases?
• How do I use it?
• How do I deploy it?
19
https://www.mongodb.com/download-center
20
Unpack and Start The Server
$ tar xf mongodb-osx-x86_64-enterprise-3.2.0.tgz
$ mkdir -p ~/mydb/data
$ mongodb-osx-x86_64-enterprise-3.2.0/bin/mongod 
> --dbpath ~/mydb/data 
> --logpath ~/mydb/mongod.log 
> --fork
about to fork child process, waiting until server is
ready for connections.
forked process: 6517
child process started successfully, parent exiting
21
Verify Operation
$ mongodb-osx-x86_64-enterprise-3.2.0/bin/mongo
MongoDB shell version: 3.2.0
connecting to: 127.0.0.1:27017/test
Server has startup warnings:
2016-01-01T12:44:01.646-0500 I CONTROL [initandlisten]
2016-01-01T12:44:01.646-0500 I CONTROL [initandlisten] ** WARNING:
soft rlimits too low. Number of files is 256, should be at least
1000
MongoDB Enterprise > use mug
switched to db mug
MongoDB Enterprise > db.foo.insert({name:”bob”,hd: new ISODate()});
MongoDB Enterprise > db.foo.insert({name:"buzz"});
MongoDB Enterprise > db.foo.insert({pets:["dog","cat"]});
MongoDB Enterprise > db.foo.find();
{ "_id" : ObjectId("5686cef538ea4981e63111dd"), "name" : "bob", "hd"
: ISODate("2016-01-01T19:09:41.442Z") }
{ "_id" : ObjectId("5686…79d5"), "name" : "buzz" }
{ "_id" : ObjectId("5686…79d6"), "pets" : [ "dog", "cat" ] }
22
The Simple Java App
import com.mongodb.client.*;
import com.mongodb.*;
import java.util.Map;
public class mug1 {
public static void main(String[] args) {
try {
MongoClient mongoClient = new MongoClient();
MongoDatabase db = mongoClient.getDatabase("mug”);
MongoCollection coll = db.getCollection("foo");
MongoCursor c = coll.find().iterator();
while(c.hasNext()) {
Map doc = (Map) c.next();
System.out.println(doc);
}
} catch(Exception e) {
// ...
}
}
}
23
Compile and Run!
$ curl -o mongodb-driver-3.0.4.jar
https://oss.sonatype.org/content/repositories/releases/org
/mongodb/mongodb-driver/3.0.4/mongodb-driver-3.0.4.jar
$ javac –cp mongo-java-driver-3.0.4.jar:. mug1.java
$ java –cp mongo-java-driver-3.0.4.jar:. mug1
(logger output)
Document{{_id=5686cef538ea4981e63111dd, name=bob,
hd=Fri Jan 01 14:09:41 EST 2016}}
Document{{_id=5686c71338ea4981e63111d6, name=buzz}}
Document{{_id=5686c71938ea4981e63111d7, pets=[dog, cat]}}
24
The Same App in python
from pymongo import MongoClient
client = MongoClient()
db = client.mug
coll = db.foo
for c in coll.find():
print c
$ python mug1.py
{u'_id': ObjectId('5686cef538ea4981e63111dd'), u'name': u'bob',
u'hd': datetime.datetime(2016, 1, 1, 19, 9, 41, 442000)}
{u'_id': ObjectId('5686f54b38ea4981e631124c'), u'name': u'buzz'}
{u'_id': ObjectId('5686f55138ea4981e631124d'), u'pets': [u'dog',
u'cat']}
25
…and, as expected in Perl…
$ perl -MMongoDB -MData::Dumper –e 'my $c =
MongoDB::MongoClient->new()->get_database("mug")-
>get_collection("foo")->find(); while($c->has_next()) {
print Dumper($c->next()); }’
$VAR1 = { '_id' => bless( {'value' => '5686cef538ea4981e63111dd’},
'MongoDB::OID' ),
'hd' => bless( {
'local_rd_secs' => 68981,
'rd_nanosecs' => 442000000, // etc
}, 'DateTime' ),
'name' => 'bob'
};
$VAR1 = { '_id' => bless( {'value' => '5686c71338ea4981e63111d6’},
'MongoDB::OID' ),
'name' => 'buzz'
};
$VAR1 = { 'pets' => [ 'dog’,'cat’],
'_id' => bless( {'value' => '5686c71938ea4981e63111d7’},
'MongoDB::OID' )
};
26
Drivers A’Plenty
Java
Python
Perl
Ruby
JavaScript
Haskell
…and more
Factory
Community
Document Validation: Stronger Than
Schema…?
> db.createCollection(”contacts", { "validator":
{ $or: [
{ $and: [ { “vers": 1},
{ ”customer_id": {$type: “string”} }
]
},
{ $and: [ { "vers": 2},
{ ”customer_id": {$type: “string”} },
{ $or: [
{ ”name.f": {$type: “string”},
”name.l": {$type: “string”}}
,
{ ”ssn": {$type: “string”}}
]
}
]
}]});
A Slightly Bigger Example
Relational MongoDB
{ vers: 1,
customer_id : 1,
name : {
“f”:"Mark”,
“l”:"Smith” },
city : "San Francisco",
phones: [ {
number : “1-212-777-1212”,
dnc : true,
type : “home”
},
{
number : “1-212-777-1213”,
type : “cell”
}]
}
Customer
ID
First Name Last Name City
0 John Doe New York
1 Mark Smith San Francisco
2 Jay White Dallas
3 Meagan White London
4 Edward Daniels Boston
Phone Number Type DNC
Customer
ID
1-212-555-1212 home T 0
1-212-555-1213 home T 0
1-212-555-1214 cell F 0
1-212-777-1212 home T 1
1-212-777-1213 cell (null) 1
1-212-888-1212 home F 2
29
MongoDB Queries Are Expressive
SQL select A.did, A.lname, A.hiredate, B.type,
B.number from contact A left outer join phones B
on (B.did = A.did) where b.type = ’home' or
A.hiredate > '2014-02-02'::date
MongoDB CLI db.contacts.find({"$or”: [
{"phones.type":”home”},
{"hiredate": {”$gt": new ISODate("2014-
02-02")}}
]});
Find all contacts with at least one home phone or
hired after 2014-02-02
30
MongoDB Aggregation Is Powerful
Sum the different types of phones and create a list
of the owners if there is more than 1 of that type
> db.contacts.aggregate([
{$unwind: "$phones"}
,{$group: {"_id": "$phones.t", "count": {$sum:1},
"names": {$push: "$name"} }}
,{$match: {"count": {$gt: 1}}}
]);
{ "_id" : "home", "count" : 2, "names" : [
{ "f" : "John", "l" : "Doe" },
{ "f" : "Mark", "l" : "Smith" } ] }
{ "_id" : "cell", "count" : 4, "names" : [
{ "f" : "John", "l" : "Doe" },
{ "f" : "Meagan", "l" : "White" },
{ "f" : "Edward", "l" : "Daniels” }
{ "f" : "Mark", "l" : "Smith" } ] }
31
$lookup: “Left Outer Join++”
> db.leases.aggregate([ ]);
{
"_id" : ObjectId("5642559e0d4f2076a43584fc"),
"leaseID" : "A5",
"sku" : "GD652",
"origDate" : ISODate("2010-01-01T00:00:00Z"),
"histDate" : ISODate("2010-10-28T00:00:00Z"),
"monthlyDue" : 10,
"vers" : 11,
"delinq" : { "d30" : 10, "d60" : 10, "d90" : 60
},
"credit" : 0
}
// 66 more ….
Step 1: Get a sense of the raw material
32
$lookup: “Left Outer Join++”
Step 2: Group leases by SKU and capture count and max value of 90
day delinquency
> db.leases.aggregate([
{$group: { _id: "$sku", n:{$sum:1},
max90:{$max:"$delinq.d90"} }}
]);
{ "_id" : "AC775", "n" : 27, "max90" : 20 }
{ "_id" : "AB123", "n" : 26, "max90" : 5 }
{ "_id" : "GD652", "n" : 14, "max90" : 80 }
33
$lookup: “Left Outer Join++”
Step 3: Reverse sort and then limit to the top 2
> db.leases.aggregate([
{$group: { _id: "$sku", n:{$sum:1},
max90:{$max:"$delinq.d90"} }}
,{$sort: {max90:-1}}
,{$limit: 2}
]);
{ "_id" : "GD652", "n" : 14, "max90" : 80 }
{ "_id" : "AC775", "n" : 27, "max90" : 20 }
34
$lookup: “Left Outer Join++”
Step 4: $lookup to product collection and assign to new field
> db.leases.aggregate([
{$group: { _id: "$sku", n:{$sum:1},
max90:{$max:"$delinq.d90"} }}
,{$sort: {max90:-1}}
,{$limit: 2}
,{$lookup: { from: "products", localField: "_id", foreignField:
"productSKU", as:"productData"}}
]);
{ "_id" : "GD652”, "n" : 14, "max90" : 80,
"productData" : [
{
"_id" : ObjectId("5642559e0d4f2076a43584b5"),
"productType" : "rigidDumptruck",
"productSKU" : "GD652",
"properties" : {
"model" : "TR45",
"payload" : {
"std" : 45,
"unit" : "UStons"
},
35
$lookup: “Left Outer Join++”
Step 5: Trim excess data away, leaving just type
> db.leases.aggregate([
{$group: { _id: "$sku", n:{$sum:1},
max90:{$max:"$delinq.d90"} }}
,{$sort: {max90:-1}}
,{$limit: 2}
,{$lookup: { from: "products", localField: "_id",
foreignField: "productSKU", as:"productData"}}
,{$project: { _id:1, n:1, max90:1, type:
"$productData.productType"}}
]);
{"_id”:"GD652”,"n”:14,"max90”:80,"type”:[”dumptruck”]}
{"_id”:"AC775”,"n”:27,"max90”:20,"type”:["loader”]}
Agenda
• What is MongoDB?
• What are some good use cases?
• How do I use it?
• How do I deploy it?
37
• Single-click provisioning
• Scaling & upgrades
• Admin tasks
• Monitoring with charts
• Dashboards and alerts on 100+
metrics
• Backup and restore with point-in-
time recovery
• Support for sharded clusters
MongoDB Ops/Cloud Manager
38
MongoDB High Availability
mongod
Application
DRIVER
39
MongoDB High Availability
PRIMARY
Application
DRIVER
secondary
secondary
The Replica Set
• 1 Primary
• 2 – 48 Secondaries
• Greatest failure isolation: Locally
attached storage (spinning or SSD)
• Less failure isolation: SAN, FLASH
40
Automatic, Seamless Failover
xxxxxxxx
Application
DRIVER
PRIMARY
secondary
41
HA and DR Are Isomorphic
PRIMARY
Application
DRIVER
secondary secondary Dual Data
Center HA/DR
Replica Set
secondary
Arbiter
(DC3 or cloud)
Data Center 1 Data Center 2
42
MongoDB Scalability
PRIMARY
Application
DRIVER
secondary
secondary
What If:
1. Workload bottlenecks network or disk?
2. Data footprint starts to get large (e.g. 5TB)?
3. Regulations demand physical domicile of
data in-region?
4. Growth profile uncertain?
5. Budget prohibits buying capacity up-front?
43
Horizontal Scalability Through Sharding
PRIMARY
Application
DRIVER
secondary
secondary
PRIMARY
secondary
secondary
PRIMARY
secondary
secondary
mongos
Three Sharding Models:
1. Range
2. Tag
3. Hash
…
Shard 1
Symbols A-D
Shard 2
Symbols E-H
Shard n
Symbols ?-Z
44
For More Information
Resource Location
Case Studies mongodb.com/customers
Presentations mongodb.com/presentations
Free Online Training education.mongodb.com
Webinars and Events mongodb.com/events
Documentation docs.mongodb.org
MongoDB Downloads mongodb.com/download
Additional Info info@mongodb.com
Questions & Answers
Thank You

More Related Content

What's hot

Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Db
chriskite
 

What's hot (20)

MongoDB
MongoDBMongoDB
MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Indexing with MongoDB
Indexing with MongoDBIndexing with MongoDB
Indexing with MongoDB
 
MongoDB presentation
MongoDB presentationMongoDB presentation
MongoDB presentation
 
MongodB Internals
MongodB InternalsMongodB Internals
MongodB Internals
 
Introduction to mongodb
Introduction to mongodbIntroduction to mongodb
Introduction to mongodb
 
An introduction to MongoDB
An introduction to MongoDBAn introduction to MongoDB
An introduction to MongoDB
 
Data Modeling for MongoDB
Data Modeling for MongoDBData Modeling for MongoDB
Data Modeling for MongoDB
 
Introducing MongoDB Atlas
Introducing MongoDB AtlasIntroducing MongoDB Atlas
Introducing MongoDB Atlas
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
Sizing Your MongoDB Cluster
Sizing Your MongoDB ClusterSizing Your MongoDB Cluster
Sizing Your MongoDB Cluster
 
MongoDB Fundamentals
MongoDB FundamentalsMongoDB Fundamentals
MongoDB Fundamentals
 
MongoDB.pptx
MongoDB.pptxMongoDB.pptx
MongoDB.pptx
 
Introduction to MongoDB.pptx
Introduction to MongoDB.pptxIntroduction to MongoDB.pptx
Introduction to MongoDB.pptx
 
MongoDB Aggregation Framework
MongoDB Aggregation FrameworkMongoDB Aggregation Framework
MongoDB Aggregation Framework
 
Migrating to MongoDB: Best Practices
Migrating to MongoDB: Best PracticesMigrating to MongoDB: Best Practices
Migrating to MongoDB: Best Practices
 
Intro To Mongo Db
Intro To Mongo DbIntro To Mongo Db
Intro To Mongo Db
 
Migrating from RDBMS to MongoDB
Migrating from RDBMS to MongoDBMigrating from RDBMS to MongoDB
Migrating from RDBMS to MongoDB
 
Mongo db dhruba
Mongo db dhrubaMongo db dhruba
Mongo db dhruba
 

Similar to Introduction to MongoDB

Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
Murat Çakal
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revised
MongoDB
 

Similar to Introduction to MongoDB (20)

Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011Mongo Web Apps: OSCON 2011
Mongo Web Apps: OSCON 2011
 
Webinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev TeamsWebinar: General Technical Overview of MongoDB for Dev Teams
Webinar: General Technical Overview of MongoDB for Dev Teams
 
Building your first app with MongoDB
Building your first app with MongoDBBuilding your first app with MongoDB
Building your first app with MongoDB
 
Building web applications with mongo db presentation
Building web applications with mongo db presentationBuilding web applications with mongo db presentation
Building web applications with mongo db presentation
 
Building Your First MongoDB App ~ Metadata Catalog
Building Your First MongoDB App ~ Metadata CatalogBuilding Your First MongoDB App ~ Metadata Catalog
Building Your First MongoDB App ~ Metadata Catalog
 
MongoDB
MongoDBMongoDB
MongoDB
 
Mongodb intro
Mongodb introMongodb intro
Mongodb intro
 
MongoDB at FrozenRails
MongoDB at FrozenRailsMongoDB at FrozenRails
MongoDB at FrozenRails
 
MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011MongoDB, PHP and the cloud - php cloud summit 2011
MongoDB, PHP and the cloud - php cloud summit 2011
 
Analytics with MongoDB Aggregation Framework and Hadoop Connector
Analytics with MongoDB Aggregation Framework and Hadoop ConnectorAnalytics with MongoDB Aggregation Framework and Hadoop Connector
Analytics with MongoDB Aggregation Framework and Hadoop Connector
 
MongoDB Evenings Houston: What's the Scoop on MongoDB and Hadoop? by Jake Ang...
MongoDB Evenings Houston: What's the Scoop on MongoDB and Hadoop? by Jake Ang...MongoDB Evenings Houston: What's the Scoop on MongoDB and Hadoop? by Jake Ang...
MongoDB Evenings Houston: What's the Scoop on MongoDB and Hadoop? by Jake Ang...
 
MongoDB Evenings Dallas: What's the Scoop on MongoDB & Hadoop
MongoDB Evenings Dallas: What's the Scoop on MongoDB & HadoopMongoDB Evenings Dallas: What's the Scoop on MongoDB & Hadoop
MongoDB Evenings Dallas: What's the Scoop on MongoDB & Hadoop
 
Introduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUWIntroduction to MongoDB at IGDTUW
Introduction to MongoDB at IGDTUW
 
Eagle6 mongo dc revised
Eagle6 mongo dc revisedEagle6 mongo dc revised
Eagle6 mongo dc revised
 
Eagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational AwarenessEagle6 Enterprise Situational Awareness
Eagle6 Enterprise Situational Awareness
 
Back to Basics Webinar 2 - Your First MongoDB Application
Back to  Basics Webinar 2 - Your First MongoDB ApplicationBack to  Basics Webinar 2 - Your First MongoDB Application
Back to Basics Webinar 2 - Your First MongoDB Application
 
Back to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB ApplicationBack to Basics Webinar 2: Your First MongoDB Application
Back to Basics Webinar 2: Your First MongoDB Application
 
Back to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDBBack to Basics, webinar 2: La tua prima applicazione MongoDB
Back to Basics, webinar 2: La tua prima applicazione MongoDB
 
Back to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDBBack to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDB
 
Online | MongoDB Atlas on GCP Workshop
Online | MongoDB Atlas on GCP Workshop Online | MongoDB Atlas on GCP Workshop
Online | MongoDB Atlas on GCP Workshop
 

More from MongoDB

More from MongoDB (20)

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

Recently uploaded

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 

Recently uploaded (20)

Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024Axa Assurance Maroc - Insurer Innovation Award 2024
Axa Assurance Maroc - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
Emergent Methods: Multi-lingual narrative tracking in the news - real-time ex...
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 

Introduction to MongoDB

  • 1. Intro To MongoDB Buzz Moschetti Enterprise Architect, MongoDB buzz.moschetti@mongodb.com @buzzmoschetti
  • 2. Who is Talking To You? • Yes, I use “Buzz” on my business cards • Former Investment Bank Chief Architect at JPMorganChase and Bear Stearns • Over 30 years of designing and building systems • Big and small • Super-specialized to broadly useful in any vertical • “Traditional” to completely disruptive • Advocate of language leverage and strong factoring • Inventor of perl DBI/DBD • Not an award winner for PowerPoint • Still programming – using emacs, of course
  • 3. Agenda • What is MongoDB? • What are some good use cases? • How do I use it? • How do I deploy it?
  • 4. MongoDB: The Leading NoSQL Database Document Data Model Open- Source Fully Featured High Performance Scalable { name: “John Smith”, pfxs: [“Dr.”,”Mr.”], address: “10 3rd St.”, phones: [ { number: “555-1212”, type: “land” }, { number: “444-1212”, type: “mobile” } ] }
  • 5. 5 The best way to run MongoDB Automated. Supported. Secured. Features beyond those in the community edition: Enterprise-Grade Support Commercial License Ops Manager or Cloud Manager Premium Encrypted & In-Memory Storage Engines MongoDB Compass BI Connector (SQL Bridge) Advanced Security Platform Certification On-Demand Training MongoDB Enterprise Edition
  • 6. Company Vital Stats 500+ employees 2000+ customers Over $311 million in funding Offices in NY & Palo Alto and across EMEA, and APAC
  • 8. RDBMS MongoDB Database Database Table Collection Index Index Row Document Column Field Join Embedding & Linking & $lookup Terminology
  • 9. { _id: “123”, title: "MongoDB: The Definitive Guide", authors: [ { _id: "kchodorow", name: "Kristina Chodorow“ }, { _id: "mdirold", name: “Mike Dirolf“ } ], published_date: ISODate(”2010-09-24”), pages: 216, language: "English", thumbnail: BinData(0,"AREhMQ=="), publisher: { name: "O’Reilly Media", founded: 1980, locations: ["CA”, ”NY” ] } } The Data Is The Schema
  • 10. > db.authors.find() { _id: ”X12", name: { first: "Kristina”, last: “Chodorow” }, personalData: { favoritePets: [ “bird”, “dog” ], awards: [ {name: “Hugo”, when: 1983}, {name: “SSFX”, when: 1992} ] } } { _id: ”Y45", name: { first: ”Mike”, last: “Dirolf” } , personalData: { dob: ISODate(“1970-04-05”) } } Treat Your Data More Like Objects
  • 11. // Java: maps DBObject query = new BasicDBObject(”publisher.founded”, 1980)); Map m = collection.findOne(query); Date pubDate = (Date)m.get(”published_date”); // java.util.Date List locs = (List)m.get(”locations”); // Javascript: objects m = collection.findOne({”publisher.founded” : 1980}); pubDate = m.published_date; // ISODate year = pubDate.getUTCFullYear(); # Python: dictionaries m = coll.find_one({”publisher.founded” : 1980 }); pubDate = m[”pubDate”].year # datetime.datetime Documents Natively Map to Language
  • 12. 12 Traditional Data Design • Static, Uniform Scalar Data • Rectangles • Low-level, physical representation
  • 13. 13 Document Data Design • Flexible, Rich Shapes • Objects • High-level, business representation
  • 14. Agenda • What is MongoDB? • What are some good use cases? • How do I use it? • How do I deploy it?
  • 15. 15 MongoDB 3.0 Set The Stage… 7x-10x Performance, 50%-80% Less Storage How: WiredTiger Storage Engine • Same data model, query language, & ops • 100% backwards compatible API • Non-disruptive upgrade • Storage savings driven by native compression • Write performance gains driven by – Document-level concurrency control – More efficient use of HW threads • Much better ability to scale vertically MongoDB 3.0MongoDB 2.6 Performance
  • 16. 16 MongoDB 3.2 : Efficient Enterprise MongoDB • Much better ability to scale vertically + • Document Validation Rules • Encryption at rest • BI Connector (SQL bridge) • MongoDB Compass • New Relic & AppDynamics integration • Backup snapshots on filesystem • Advanced Full-text languages • $lookup (“left outer JOIN”) More general-purpose solutions
  • 17. 17 MongoDB Sweet Spot Use Cases Big Data Product & Asset Catalogs Security & Fraud Internet of Things Database-as- a- Service Mobile Apps Customer Data Management Single View Social & Collaboration Content Management Intelligence Agencies Top Investment and Retail Banks Top Global Shipping Company Top Industrial Equipment Manufacturer Top Media Company Top Investment and Retail Banks Complex Data Management Top Investment and Retail Banks Embedded / ISV Cushman & Wakefield
  • 18. Agenda • What is MongoDB? • What are some good use cases? • How do I use it? • How do I deploy it?
  • 20. 20 Unpack and Start The Server $ tar xf mongodb-osx-x86_64-enterprise-3.2.0.tgz $ mkdir -p ~/mydb/data $ mongodb-osx-x86_64-enterprise-3.2.0/bin/mongod > --dbpath ~/mydb/data > --logpath ~/mydb/mongod.log > --fork about to fork child process, waiting until server is ready for connections. forked process: 6517 child process started successfully, parent exiting
  • 21. 21 Verify Operation $ mongodb-osx-x86_64-enterprise-3.2.0/bin/mongo MongoDB shell version: 3.2.0 connecting to: 127.0.0.1:27017/test Server has startup warnings: 2016-01-01T12:44:01.646-0500 I CONTROL [initandlisten] 2016-01-01T12:44:01.646-0500 I CONTROL [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 MongoDB Enterprise > use mug switched to db mug MongoDB Enterprise > db.foo.insert({name:”bob”,hd: new ISODate()}); MongoDB Enterprise > db.foo.insert({name:"buzz"}); MongoDB Enterprise > db.foo.insert({pets:["dog","cat"]}); MongoDB Enterprise > db.foo.find(); { "_id" : ObjectId("5686cef538ea4981e63111dd"), "name" : "bob", "hd" : ISODate("2016-01-01T19:09:41.442Z") } { "_id" : ObjectId("5686…79d5"), "name" : "buzz" } { "_id" : ObjectId("5686…79d6"), "pets" : [ "dog", "cat" ] }
  • 22. 22 The Simple Java App import com.mongodb.client.*; import com.mongodb.*; import java.util.Map; public class mug1 { public static void main(String[] args) { try { MongoClient mongoClient = new MongoClient(); MongoDatabase db = mongoClient.getDatabase("mug”); MongoCollection coll = db.getCollection("foo"); MongoCursor c = coll.find().iterator(); while(c.hasNext()) { Map doc = (Map) c.next(); System.out.println(doc); } } catch(Exception e) { // ... } } }
  • 23. 23 Compile and Run! $ curl -o mongodb-driver-3.0.4.jar https://oss.sonatype.org/content/repositories/releases/org /mongodb/mongodb-driver/3.0.4/mongodb-driver-3.0.4.jar $ javac –cp mongo-java-driver-3.0.4.jar:. mug1.java $ java –cp mongo-java-driver-3.0.4.jar:. mug1 (logger output) Document{{_id=5686cef538ea4981e63111dd, name=bob, hd=Fri Jan 01 14:09:41 EST 2016}} Document{{_id=5686c71338ea4981e63111d6, name=buzz}} Document{{_id=5686c71938ea4981e63111d7, pets=[dog, cat]}}
  • 24. 24 The Same App in python from pymongo import MongoClient client = MongoClient() db = client.mug coll = db.foo for c in coll.find(): print c $ python mug1.py {u'_id': ObjectId('5686cef538ea4981e63111dd'), u'name': u'bob', u'hd': datetime.datetime(2016, 1, 1, 19, 9, 41, 442000)} {u'_id': ObjectId('5686f54b38ea4981e631124c'), u'name': u'buzz'} {u'_id': ObjectId('5686f55138ea4981e631124d'), u'pets': [u'dog', u'cat']}
  • 25. 25 …and, as expected in Perl… $ perl -MMongoDB -MData::Dumper –e 'my $c = MongoDB::MongoClient->new()->get_database("mug")- >get_collection("foo")->find(); while($c->has_next()) { print Dumper($c->next()); }’ $VAR1 = { '_id' => bless( {'value' => '5686cef538ea4981e63111dd’}, 'MongoDB::OID' ), 'hd' => bless( { 'local_rd_secs' => 68981, 'rd_nanosecs' => 442000000, // etc }, 'DateTime' ), 'name' => 'bob' }; $VAR1 = { '_id' => bless( {'value' => '5686c71338ea4981e63111d6’}, 'MongoDB::OID' ), 'name' => 'buzz' }; $VAR1 = { 'pets' => [ 'dog’,'cat’], '_id' => bless( {'value' => '5686c71938ea4981e63111d7’}, 'MongoDB::OID' ) };
  • 27. Document Validation: Stronger Than Schema…? > db.createCollection(”contacts", { "validator": { $or: [ { $and: [ { “vers": 1}, { ”customer_id": {$type: “string”} } ] }, { $and: [ { "vers": 2}, { ”customer_id": {$type: “string”} }, { $or: [ { ”name.f": {$type: “string”}, ”name.l": {$type: “string”}} , { ”ssn": {$type: “string”}} ] } ] }]});
  • 28. A Slightly Bigger Example Relational MongoDB { vers: 1, customer_id : 1, name : { “f”:"Mark”, “l”:"Smith” }, city : "San Francisco", phones: [ { number : “1-212-777-1212”, dnc : true, type : “home” }, { number : “1-212-777-1213”, type : “cell” }] } Customer ID First Name Last Name City 0 John Doe New York 1 Mark Smith San Francisco 2 Jay White Dallas 3 Meagan White London 4 Edward Daniels Boston Phone Number Type DNC Customer ID 1-212-555-1212 home T 0 1-212-555-1213 home T 0 1-212-555-1214 cell F 0 1-212-777-1212 home T 1 1-212-777-1213 cell (null) 1 1-212-888-1212 home F 2
  • 29. 29 MongoDB Queries Are Expressive SQL select A.did, A.lname, A.hiredate, B.type, B.number from contact A left outer join phones B on (B.did = A.did) where b.type = ’home' or A.hiredate > '2014-02-02'::date MongoDB CLI db.contacts.find({"$or”: [ {"phones.type":”home”}, {"hiredate": {”$gt": new ISODate("2014- 02-02")}} ]}); Find all contacts with at least one home phone or hired after 2014-02-02
  • 30. 30 MongoDB Aggregation Is Powerful Sum the different types of phones and create a list of the owners if there is more than 1 of that type > db.contacts.aggregate([ {$unwind: "$phones"} ,{$group: {"_id": "$phones.t", "count": {$sum:1}, "names": {$push: "$name"} }} ,{$match: {"count": {$gt: 1}}} ]); { "_id" : "home", "count" : 2, "names" : [ { "f" : "John", "l" : "Doe" }, { "f" : "Mark", "l" : "Smith" } ] } { "_id" : "cell", "count" : 4, "names" : [ { "f" : "John", "l" : "Doe" }, { "f" : "Meagan", "l" : "White" }, { "f" : "Edward", "l" : "Daniels” } { "f" : "Mark", "l" : "Smith" } ] }
  • 31. 31 $lookup: “Left Outer Join++” > db.leases.aggregate([ ]); { "_id" : ObjectId("5642559e0d4f2076a43584fc"), "leaseID" : "A5", "sku" : "GD652", "origDate" : ISODate("2010-01-01T00:00:00Z"), "histDate" : ISODate("2010-10-28T00:00:00Z"), "monthlyDue" : 10, "vers" : 11, "delinq" : { "d30" : 10, "d60" : 10, "d90" : 60 }, "credit" : 0 } // 66 more …. Step 1: Get a sense of the raw material
  • 32. 32 $lookup: “Left Outer Join++” Step 2: Group leases by SKU and capture count and max value of 90 day delinquency > db.leases.aggregate([ {$group: { _id: "$sku", n:{$sum:1}, max90:{$max:"$delinq.d90"} }} ]); { "_id" : "AC775", "n" : 27, "max90" : 20 } { "_id" : "AB123", "n" : 26, "max90" : 5 } { "_id" : "GD652", "n" : 14, "max90" : 80 }
  • 33. 33 $lookup: “Left Outer Join++” Step 3: Reverse sort and then limit to the top 2 > db.leases.aggregate([ {$group: { _id: "$sku", n:{$sum:1}, max90:{$max:"$delinq.d90"} }} ,{$sort: {max90:-1}} ,{$limit: 2} ]); { "_id" : "GD652", "n" : 14, "max90" : 80 } { "_id" : "AC775", "n" : 27, "max90" : 20 }
  • 34. 34 $lookup: “Left Outer Join++” Step 4: $lookup to product collection and assign to new field > db.leases.aggregate([ {$group: { _id: "$sku", n:{$sum:1}, max90:{$max:"$delinq.d90"} }} ,{$sort: {max90:-1}} ,{$limit: 2} ,{$lookup: { from: "products", localField: "_id", foreignField: "productSKU", as:"productData"}} ]); { "_id" : "GD652”, "n" : 14, "max90" : 80, "productData" : [ { "_id" : ObjectId("5642559e0d4f2076a43584b5"), "productType" : "rigidDumptruck", "productSKU" : "GD652", "properties" : { "model" : "TR45", "payload" : { "std" : 45, "unit" : "UStons" },
  • 35. 35 $lookup: “Left Outer Join++” Step 5: Trim excess data away, leaving just type > db.leases.aggregate([ {$group: { _id: "$sku", n:{$sum:1}, max90:{$max:"$delinq.d90"} }} ,{$sort: {max90:-1}} ,{$limit: 2} ,{$lookup: { from: "products", localField: "_id", foreignField: "productSKU", as:"productData"}} ,{$project: { _id:1, n:1, max90:1, type: "$productData.productType"}} ]); {"_id”:"GD652”,"n”:14,"max90”:80,"type”:[”dumptruck”]} {"_id”:"AC775”,"n”:27,"max90”:20,"type”:["loader”]}
  • 36. Agenda • What is MongoDB? • What are some good use cases? • How do I use it? • How do I deploy it?
  • 37. 37 • Single-click provisioning • Scaling & upgrades • Admin tasks • Monitoring with charts • Dashboards and alerts on 100+ metrics • Backup and restore with point-in- time recovery • Support for sharded clusters MongoDB Ops/Cloud Manager
  • 39. 39 MongoDB High Availability PRIMARY Application DRIVER secondary secondary The Replica Set • 1 Primary • 2 – 48 Secondaries • Greatest failure isolation: Locally attached storage (spinning or SSD) • Less failure isolation: SAN, FLASH
  • 41. 41 HA and DR Are Isomorphic PRIMARY Application DRIVER secondary secondary Dual Data Center HA/DR Replica Set secondary Arbiter (DC3 or cloud) Data Center 1 Data Center 2
  • 42. 42 MongoDB Scalability PRIMARY Application DRIVER secondary secondary What If: 1. Workload bottlenecks network or disk? 2. Data footprint starts to get large (e.g. 5TB)? 3. Regulations demand physical domicile of data in-region? 4. Growth profile uncertain? 5. Budget prohibits buying capacity up-front?
  • 43. 43 Horizontal Scalability Through Sharding PRIMARY Application DRIVER secondary secondary PRIMARY secondary secondary PRIMARY secondary secondary mongos Three Sharding Models: 1. Range 2. Tag 3. Hash … Shard 1 Symbols A-D Shard 2 Symbols E-H Shard n Symbols ?-Z
  • 44. 44 For More Information Resource Location Case Studies mongodb.com/customers Presentations mongodb.com/presentations Free Online Training education.mongodb.com Webinars and Events mongodb.com/events Documentation docs.mongodb.org MongoDB Downloads mongodb.com/download Additional Info info@mongodb.com

Editor's Notes

  1. HELLO! This is Buzz Moschetti at MongoDB, and welcome to today’s webinar entitled “Thinking in Documents”, part of our Back To Basics series. If your travel plans today do not include exploring the document model in MongoDB then please exit the aircraft immediately and see an agent at the gate Otherwise – WELCOME ABOARD for about the next hour.
  2. Let’s talk about some the terms. JOINS: RDBMS uses Join to stich together fundamentally simple things into larger, more complex data. MongoDB uses embedding of data within data and linking to produce the same result
  3. There are three themes that are important to grasp when Thinking In Documents in MongoDB and these will be reinforced throughout the presentation. First, great schema design…. I’ll repeat it: great… This is not new or something revolutionary to MongoDB. It is something we have been doing all along in the construction of solutions. Sometimes well, sometimes not. It’s just that the data structures and APIs used by MongoDB make it much easier to satisfy the first two bullet points. Particularly for an up-stack software engineer kind of person like myself, the ease and power of well-harmonizing your persistence with your code – java, javascript, perl, python – is a vital part of ensuring your overall information architecture is robust. Part of the exercise also involves candidly addressing legacy RDBMS issues that we see over and over again after 40 years, like schema explosion and field overloading and flattening Boils down to success = “schema” + code
  4. Let’s talk about some the terms. JOINS: RDBMS uses Join to stich together fundamentally simple things into larger, more complex data. MongoDB uses embedding of data within data and linking to produce the same result
  5. Very briefly, a little bit about the person talking to you today over the net.
  6. Yep!
  7. Let’s talk about some the terms. JOINS: RDBMS uses Join to stich together fundamentally simple things into larger, more complex data. MongoDB uses embedding of data within data and linking to produce the same result
  8. Let’s talk about some the terms. JOINS: RDBMS uses Join to stich together fundamentally simple things into larger, more complex data. MongoDB uses embedding of data within data and linking to produce the same result
  9. A document is not a PDF or a MS word artifact. A document a term for a rich shape. Structures of structures of lists of structures that ultimately at the leaves have familiar scalars like int, double, datetimes, and string. In this example we see also that we’re carrying a thumbnail photo in a binary byte array type; that’s natively supported as well. This is different than the traditional row-column approach used in RDBMS. Another important difference is that In MongoDB, it is not required for every document in a collection to be the same shape; shapes can VARY With the upcoming release of 3.2, we will be supporting documentation validation so in those designs where certain fields and their types are absolutely mandatory, we’ll be able to enforce that at the DB engine level similar to – but not exactly like – traditional schemas. Truth is in most non-trivial systems, even with RDBMS and stored procs, etc. plenty of validation and logic is being handled outside the database.. Now here is something very important: For the purposes of the webinar, we will be seeing this “to-string” representation of a document as it is emitted from the MongoDB CLI. This is easy to read and gets the structural design points across nicely. But make no mistake: you want most of your actual software interaction with MongoDB (and frankly any DB) to be via high fidelity types, not a big string with whitespaces and CR and quotes and whatnot.
  10. This is a very, very exciting part of MongoDB. No need to come up with userDefined column 1, column 2, etc. We see here that Kristina and Mike have very different substructures inside the personalData field. We call this polymorphism: the variation of shape from document-to-document within the same collection. The library application logic only is looking for a field called “personalData”; actions will be taken dynamically based on the shape and types in the substructure! For example, It is a very straightforward exercise to recursively “walk” the structure and construct a panel in a GUI – especially if you are using AngularJS and the MEAN stack (MongoDB / Express / Angular / Node.js ) No need to use XML or blobs or serialized objects. It’s all native MongoDB -- and documents are represented in the form most easily natively manipulated by the language Every field is queryable and if so desired, indexable! Documents that do not contain fields in a query predicate are simply treated as unset.
  11. Drivers in each language represent documents in a language-native form most appropriate for that language. Java has maps, python has dictionaries. You deal with actual objects like Dates, not strings that must be constructed or parsed. Another important note: We’ll be using query functionality to kill 2 birds with one stone: To show the shape of the document To show just a bit of the MongoDB query language itself including dotpath notation to “dig into” substructures Note also that in MongoDB, documents go into collections in the same shape they come out so we won’t focus on insert. This is a very different design paradigm from RDBMS, where, for example, the read-side of an operation implemented as an 8 way join is very different than the set of insert statements (some of them in a loop) required for the write side.
  12. Let’s get back to data design. … Traditional data design is characterized by some of the points above, and this is largely because the design goals and constraints of legacy RDBMS engines heavily influence the data being put into them. These platforms were designed when CPUs were slow and memory was VERY expensive. Perhaps more interesting is that the languages of the time – COBOL, FORTRAN, APL, PASCAL, C – were very compile time oriented and very rectangular in their expression of data structures. One could say rigid schema combined with these languages was in fact well-harmonized. Overall, the platform is VERY focused on the physical representation of data. For example, although most have been conflated, the legacy types of char, varchar, text, CLOB etc. to represent a string suggest a strong coupling to byte-wise storage concerns.
  13. Documents, on the other hand, are more like business entities. You’ll want to think of your data moving in and out as objects. And the types and features of Document APIs are designed to be well-harmonized with today’s programming languages – Java, C#, python, node.js, Scala , C++ -- languages that are not nearly as compile-time oriented and offer great capabilities to dynamically manipulate data and perform reflection/introspection upon it.
  14. There are three themes that are important to grasp when Thinking In Documents in MongoDB and these will be reinforced throughout the presentation. First, great schema design…. I’ll repeat it: great… This is not new or something revolutionary to MongoDB. It is something we have been doing all along in the construction of solutions. Sometimes well, sometimes not. It’s just that the data structures and APIs used by MongoDB make it much easier to satisfy the first two bullet points. Particularly for an up-stack software engineer kind of person like myself, the ease and power of well-harmonizing your persistence with your code – java, javascript, perl, python – is a vital part of ensuring your overall information architecture is robust. Part of the exercise also involves candidly addressing legacy RDBMS issues that we see over and over again after 40 years, like schema explosion and field overloading and flattening Boils down to success = “schema” + code
  15. Some quick logistics. In the last 5 to 10 mins today, we will answer the most common questions that have appeared in the webinar.
  16. Some quick logistics. In the last 5 to 10 mins today, we will answer the most common questions that have appeared in the webinar.
  17. Customer Data Management (e.g., Customer Relationship Management, Biometrics, User Profile Management) Product and Asset Catalogs (e.g., eCommerce, Inventory Management) Social and Collaboration Apps: (e.g., Social Networks and Feeds, Document and Project Collaboration Tools) Mobile Apps (e.g., for Smartphones and Tablets) Content Management (e.g, Web CMS, Document Management, Digital Asset and Metadata Management) Internet of Things / Machine to Machine (e.g., mHealth, Connected Home, Smart Meters) Security and Fraud Apps (e.g., Fraud Detection, Cyberthreat Analysis) DbaaS (Cloud Database-as-a-Service) Data Hub (Aggregating Data from Multiple Sources for Operational or Analytical Purposes) Big Data (e.g., Genomics, Clickstream Analysis, Customer Sentiment Analysis)
  18. There are three themes that are important to grasp when Thinking In Documents in MongoDB and these will be reinforced throughout the presentation. First, great schema design…. I’ll repeat it: great… This is not new or something revolutionary to MongoDB. It is something we have been doing all along in the construction of solutions. Sometimes well, sometimes not. It’s just that the data structures and APIs used by MongoDB make it much easier to satisfy the first two bullet points. Particularly for an up-stack software engineer kind of person like myself, the ease and power of well-harmonizing your persistence with your code – java, javascript, perl, python – is a vital part of ensuring your overall information architecture is robust. Part of the exercise also involves candidly addressing legacy RDBMS issues that we see over and over again after 40 years, like schema explosion and field overloading and flattening Boils down to success = “schema” + code
  19. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  20. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  21. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  22. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  23. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  24. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  25. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  26. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  27. We’ll close with something really cool – document validation that adapts to change over time. Assuming you “soft version” your documents by including a logical version ID ( in this case, a simple integer in field v) , you can maintain multiple different shapes of documents in one collection, each of them validation enforced to the version rules appropriate at the time. And again, because it is at the DB engine level, enforcement is guaranteed through all drivers. SUPER POWERFUL!
  28. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  29. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  30. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  31. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  32. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  33. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  34. Today we’ll explore data structures and schema for a library management application Good example because in general most of you have some familiarity with the entities involved and we can explore some 1:1, 1:n and other design elements
  35. There are three themes that are important to grasp when Thinking In Documents in MongoDB and these will be reinforced throughout the presentation. First, great schema design…. I’ll repeat it: great… This is not new or something revolutionary to MongoDB. It is something we have been doing all along in the construction of solutions. Sometimes well, sometimes not. It’s just that the data structures and APIs used by MongoDB make it much easier to satisfy the first two bullet points. Particularly for an up-stack software engineer kind of person like myself, the ease and power of well-harmonizing your persistence with your code – java, javascript, perl, python – is a vital part of ensuring your overall information architecture is robust. Part of the exercise also involves candidly addressing legacy RDBMS issues that we see over and over again after 40 years, like schema explosion and field overloading and flattening Boils down to success = “schema” + code
  36. On behalf of all of us at MongoDB , thank you for attending this webinar! I hope what you saw and heard today gave you some insight and clues into what you might face in your own data design efforts. Remember you can always reach out to us at MongoDB for guidance. With that, code well and be well.