SlideShare a Scribd company logo
Building your first app with MongoDB
#mongodbdays @mongodb @nleite #developers 
Building your first app 
An introduction to MongoDB 
Norberto Leite 
SA, MongoDB
First Things First!
Let’s not talk about Fußball!
Quick Introduction 
• Norberto Leite 
– SA 
– Madrid, Spain 
– norberto@mongodb.com 
– @nleite
Building your first app with MongoDB
Welcome to MongoDB Days 
Munich! 
This is YOUR conference!
Thanks for being part of the Family!
Grab our staff for anything you need!
What is MongoDB?
MongoDB is a ___________ database 
• Document 
• Open source 
• High performance 
• Horizontally scalable 
• Full featured
Document Database 
• Not for .PDF & .DOC files 
• A document is essentially an associative array 
• Document = JSON object 
• Document = PHP Array 
• Document = Python Dict 
• Document = Ruby Hash 
• etc
Open Source 
• MongoDB is an open source project 
• On GitHub 
• Licensed under the AGPL 
• Started & sponsored by MongoDB Inc (formerly 
10gen) 
• Commercial licenses available 
• Contributions welcome
High Performance 
• Written in C++ 
• Extensive use of memory-mapped files 
i.e. read-through write-through memory caching. 
• Runs nearly everywhere 
• Data serialized as BSON (fast parsing) 
• Full support for primary & secondary indexes 
• Document model = less work
Shard 1 Shard 2 Shard 3 Shard N 
Horizontally Scalable
Database Landscape
Full Featured 
• Ad Hoc queries 
• Real time aggregation 
• Rich query capabilities 
• Strongly consistent 
• Geospatial features 
• Support for most programming languages 
• Flexible schema
Setting Expectations 
• What is MongoDB 
• How to develop with MongoDB 
• Scale with MongoDB 
• Analytics 
• MMS 
• Sharding 
• Setting the correct environment
Ready to become a Pro!
mongodb.org/downloads
Running MongoDB 
$ tar –z xvf mongodb-osx-x86_64-2.6.5.tgz 
$ cd mongodb-osx-i386-2.4.4/bin 
$ mkdir –p /data/db 
$ ./mongod
Mongo Shell 
MacBook-Air-:~ $ mongo 
MongoDB shell version: 2.6.5 
connecting to: test 
> db.test.insert({text: 'Welcome to MongoDB'}) 
> db.test.find().pretty() 
{ 
"_id" : ObjectId("51c34130fbd5d7261b4cdb55"), 
"text" : "Welcome to MongoDB" 
}
Document Database
Terminology 
RDBMS MongoDB 
Table, View ➜ Collection 
Row ➜ Document 
Index ➜ Index 
Join ➜ Embedded Document 
Foreign Key ➜ Reference 
Partition ➜ Shard
Let’s Build a Blog
Let’s Build a Blog
Let’s Build a Personal Data Hub!
First step in any application is 
Determine your entities
Entities in our Data Hub 
• Accounts 
• Messages 
– emails 
– tweets 
– comments 
– streams 
• Notifications
In a relational base app 
We would start by doing schema 
design
Typical (relational) ERD 
Messages 
Email 
Tweets 
Facebook 
messages 
Alerts 
Accounts
Building your first app with MongoDB
Das ist beängstigende Sache
In a MongoDB based app 
We start building our app 
and let the schema evolve
MongoDB ERD 
Accounts 
- account 
- user 
- password 
- refresh_rate 
- uri 
Alerts 
Messages 
- id 
- time 
- account_id 
- from 
- to 
- body 
- attachments 
- text 
- user 
- time 
- retweets 
- subscribers 
- channel 
- rate 
- period 
- metrics:[] 
…
Working With MongoDB
Demo time
Switch to Your DB 
>db 
test 
> use datahub 
switching to db datahub
Create our first Document 
>var account = { 
"name": "gmail", 
"credentials": { 
"user": "norberto@mongodb.com", 
"password": "YOU WISH!" 
}, 
"smtp": "smpt.gmail.com", 
"tls": true 
}
Switch to Your DB 
>db 
test 
> use datahub 
switching to db datahub 
> db.accounts.insert( account )
Insert the Record 
> db.accounts.insert(account) 
No collection creation necessary
Find One Record 
> db.accounts.findOne() 
{ 
"_id": ObjectId("54490561150027cc775b1019"), 
"name": "gmail", 
"credentials": { 
"user": "norberto@mongodb.com", 
"password": "YOU WISH!" 
}, 
"smtp": "smpt.gmail.com", 
"tls": true 
}
_id 
• _id is the primary key in MongoDB 
• Automatically indexed 
• Automatically created as an ObjectId if not provided 
• Any unique immutable value could be used
ObjectId 
• ObjectId is a special 12 byte value 
• Guaranteed to be unique across your cluster 
• ObjectId("50804d0bd94ccab2da652599") 
|----ts-----||---mac---||-pid-||----inc-----| 
4 3 2 3
Rich Data Types 
> db.accounts.findOne() 
{ 
"_id": ObjectId("54490561150027cc775b1019"), 
"name": "gmail", 
"credentials": { 
Strings 
"user": "norberto@mongodb.com", 
"password": "YOU WISH!" 
}, 
”last_access": ISODate("2014-10-30T13:09:36.724Z"), 
"smtp": "smpt.gmail.com", 
"tls": true 
} 
Date 
Boolean
BSON
Inserting Messages (emails, tweets …) 
> db.messages.insert({ 
"_id" : ObjectId("54527e08257844421e64623f"), 
"favorited" : false, 
"contributors" : null, 
"truncated" : false, 
"text" : "converting to #java 8", 
"in_reply_to_status_id" : null, 
”hashtags”: [ "#java", ] 
… 
}
Inserting Messages (emails, tweets …) 
> db.messages.insert({ 
"_id" : ObjectId("54523d2d25784427c6fabce1"), 
"From" : "norberto@mongodb.com", 
"To" : "mongodb-user@googlegroups.com", 
"Date" : ISODate("2012-08-15T22:32:34Z"), 
"body" : { 
"text/plain" : ”Hello Munich, nice to see yalll!" 
}, 
"Subject" : ”Live From MongoDB World" 
})
Finding a Message 
> db.message.find().pretty() 
{ 
"_id" : ObjectId("54523d2d25784427c6fabce1"), 
"From" : "norberto@mongodb.com", 
"To" : "mongodb-user@googlegroups.com", 
"Date" : ISODate("2012-08-15T22:32:34Z"), 
"body" : { 
"text/plain" : ”Hello Munich, nice to see yalll!" 
}, 
"Subject" : ”Live From MongoDB World" 
} 
{ 
"_id" : ObjectId("54527e08257844421e64623f"), 
"favorited" : false, 
"contributors" : null, 
"truncated" : false, 
"text" : "converting to #java 8", 
"in_reply_to_status_id" : null, 
”hashtags”: [ "#java", ] 
… 
}
Querying An Array 
> db.article.find({"hashtags":"#java"}).pretty() 
{ 
"_id" : ObjectId("54527e08257844421e64623f"), 
"favorited" : false, 
"contributors" : null, 
"truncated" : false, 
"text" : "converting to #java 8, #programing ", 
"in_reply_to_status_id" : null, 
”hashtags”: [ "#java", "#programing"] 
… 
} 
query in JSON
Using Update to Add a Comment 
> db.messages.update({ 
"_id" : ObjectId("54523d2d25784427c6fabce1") }, 
{$set: { opened: 
{date: ISODate("2012-08-15T22:32:34Z"), user: ’Norberto'} 
} 
}) 
> 
which is a subdocument set new field on the document
Post with Comment Attached 
> db.message.findOne({"_id" : ObjectId("54523d2d25784427c6fabce1")}) 
{ 
"_id" : ObjectId("54523d2d25784427c6fabce1"), 
"From" : "norberto@mongodb.com", 
"To" : "mongodb-user@googlegroups.com", 
"Date" : ISODate("2012-08-15T22:32:34Z"), 
"body" : { 
"text/plain" : ”Hello Munich, nice to see yalll!" 
}, 
"Subject" : ”Live From MongoDB World” 
"opened" : {"date": ISODate("2012-08-15T22:32:34Z"), "user": ’Norberto'} 
} 
Find document by primary key
MongoDB Drivers
Real applications are not 
built in the shell
MongoDB has native 
bindings for over 12 
languages
Morphia 
MEAN Stack 
Java 
Python 
Perl 
Ruby 
Support for the 
most popular 
languages and 
frameworks
Building your first app with MongoDB
Great, I’m excited! What’s next?
docs.mongodb.org
Never Stop Learning!
Schema Design, Schema 
Design, Schema Design, 
Schema Design!
Legacy Migration 
1. Copy existing schema & some data to MongoDB 
2. Iterate schema design development 
Measure performance, find bottlenecks, and embed 
1. one to one associations first 
2. one to many associations next 
3. many to many associations 
3. Migrate full dataset to new schema 
New Software Application? Embed by default
Embedding over Referencing 
• Embedding is a bit like pre-joined data 
– BSON (Binary JSON) document ops are easy for the server 
• Embed (90/10 following rule of thumb) 
– When the “one” or “many” objects are viewed in the context 
of their parent 
– For performance 
– For atomicity 
• Reference 
– When you need more scaling 
– For easy consistency with “many to many” associations 
without duplicated data
It’s All About Your Application 
• Programs+Databases = (Big) Data Applications 
• Your schema is the impedance matcher 
– Design choices: normalize/denormalize, reference/embed 
– Melds programming with MongoDB for best of both 
– Flexible for development and change 
• Programs×MongoDB = Great Big Data Applications
We've introduced a lot of 
concepts here
IoT
MMS @ 
Scale Easily 
Best Practices, 
Automated 
Cut 
Management 
Overhead
Scalability @
DevOps @ 
Provision 
Upgrade 
Scale 
Continuous Backup 
Point-in-Time Recovery 
Performance Alerts
Wrapping up … 
• MongoDB is a great Developers Tool 
• Designed for : 
• Scalability 
• Flexibility 
• Performance 
• Multipurpose 
• Great Ecosystem
Well Done !
Questions?
#mongodbdays 
Obrigado! 
Norberto Leite 
norberto@mongodb.com

More Related Content

What's hot (20)

PPTX
Introduction to MongoDB
MongoDB
 
PPTX
MongoDB Days Silicon Valley: Introducing MongoDB 3.2
MongoDB
 
PDF
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
Matias Cascallares
 
PPTX
Building Your First Application with MongoDB
MongoDB
 
PPTX
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
MongoDB
 
PPTX
User Data Management with MongoDB
MongoDB
 
PPTX
Database Trends for Modern Applications: Why the Database You Choose Matters
MongoDB
 
PPTX
MongoDB 101
Abhijeet Vaikar
 
PPTX
MongoDB Days Silicon Valley: Jumpstart: Ops/Admin 101
MongoDB
 
PPTX
Webinar: Building Your First MongoDB App
MongoDB
 
PPTX
Webinar: Best Practices for Getting Started with MongoDB
MongoDB
 
PDF
Webinar: Building Your First App with MongoDB and Java
MongoDB
 
PDF
MongoDB for Coder Training (Coding Serbia 2013)
Uwe Printz
 
PDF
Mongo DB
Edureka!
 
KEY
MongoDB & Mongoid with Rails
Justin Smestad
 
PPTX
MongoDB for Developers
Ciro Donato Caiazzo
 
PPTX
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
MongoDB
 
PPTX
MongoDB Schema Design: Four Real-World Examples
Mike Friedman
 
PPTX
Intro To Mongo Db
chriskite
 
PPT
5 Pitfalls to Avoid with MongoDB
Tim Callaghan
 
Introduction to MongoDB
MongoDB
 
MongoDB Days Silicon Valley: Introducing MongoDB 3.2
MongoDB
 
The Fine Art of Schema Design in MongoDB: Dos and Don'ts
Matias Cascallares
 
Building Your First Application with MongoDB
MongoDB
 
Conceptos básicos. seminario web 3 : Diseño de esquema pensado para documentos
MongoDB
 
User Data Management with MongoDB
MongoDB
 
Database Trends for Modern Applications: Why the Database You Choose Matters
MongoDB
 
MongoDB 101
Abhijeet Vaikar
 
MongoDB Days Silicon Valley: Jumpstart: Ops/Admin 101
MongoDB
 
Webinar: Building Your First MongoDB App
MongoDB
 
Webinar: Best Practices for Getting Started with MongoDB
MongoDB
 
Webinar: Building Your First App with MongoDB and Java
MongoDB
 
MongoDB for Coder Training (Coding Serbia 2013)
Uwe Printz
 
Mongo DB
Edureka!
 
MongoDB & Mongoid with Rails
Justin Smestad
 
MongoDB for Developers
Ciro Donato Caiazzo
 
Conceptos básicos. Seminario web 4: Indexación avanzada, índices de texto y g...
MongoDB
 
MongoDB Schema Design: Four Real-World Examples
Mike Friedman
 
Intro To Mongo Db
chriskite
 
5 Pitfalls to Avoid with MongoDB
Tim Callaghan
 

Viewers also liked (20)

PDF
2016 SRA Globalization Poster_Justice_Caruson
Sandy Justice
 
PDF
Review: Leadership Frameworks
Mariam Nazarudin
 
PDF
Online Travel: Today and Tomorrow
Yanis Dzenis
 
PDF
BPM & Enterprise Middleware - Datasheet
Xpand IT
 
PDF
Cartagena Data Festival | Telling Stories with Data 2015 04-21
ulrichatz
 
PDF
O Diferencial de uma Estratégia Mobile...e Multiplataforma!
Xpand IT
 
PPTX
Old & wise(에듀시니어)
Jungku Hong
 
PPTX
MongoDB at Flight Centre Ltd
MongoDB
 
PDF
Microsoft xamarin-experience
Xpand IT
 
PDF
Introduction Pentaho 5.0
Xpand IT
 
PDF
Strongly Typed Languages and Flexible Schemas
Norberto Leite
 
PPT
онлайн бронирование модуль для турагенств
Adrian Parker
 
PPT
Introduction to jira
Xpand IT
 
PPTX
Ov big data
Hassen Dhrif
 
PPT
Science Communication 2.0: changing University attitude through Science resea...
Miquel Duran
 
PPTX
Challenges in opening up qualitative research data
lifeofdata
 
PPTX
Mgidigitalglobalization
Vera Kovaleva
 
PPTX
Heavy Metal PowerPivot Remastered
Jason Himmelstein
 
PPTX
NOSQL Session GlueCon May 2010
MongoDB
 
PDF
Revving Up Revenue By Replenishing
WhatConts
 
2016 SRA Globalization Poster_Justice_Caruson
Sandy Justice
 
Review: Leadership Frameworks
Mariam Nazarudin
 
Online Travel: Today and Tomorrow
Yanis Dzenis
 
BPM & Enterprise Middleware - Datasheet
Xpand IT
 
Cartagena Data Festival | Telling Stories with Data 2015 04-21
ulrichatz
 
O Diferencial de uma Estratégia Mobile...e Multiplataforma!
Xpand IT
 
Old & wise(에듀시니어)
Jungku Hong
 
MongoDB at Flight Centre Ltd
MongoDB
 
Microsoft xamarin-experience
Xpand IT
 
Introduction Pentaho 5.0
Xpand IT
 
Strongly Typed Languages and Flexible Schemas
Norberto Leite
 
онлайн бронирование модуль для турагенств
Adrian Parker
 
Introduction to jira
Xpand IT
 
Ov big data
Hassen Dhrif
 
Science Communication 2.0: changing University attitude through Science resea...
Miquel Duran
 
Challenges in opening up qualitative research data
lifeofdata
 
Mgidigitalglobalization
Vera Kovaleva
 
Heavy Metal PowerPivot Remastered
Jason Himmelstein
 
NOSQL Session GlueCon May 2010
MongoDB
 
Revving Up Revenue By Replenishing
WhatConts
 
Ad

Similar to Building your first app with MongoDB (20)

PDF
MongoDB
wiTTyMinds1
 
DOCX
MongoDB DOC v1.5
Tharun Srinivasa
 
PDF
Introduction to MongoDB
Mike Dirolf
 
PDF
Mongo db eveningschemadesign
MongoDB APAC
 
PDF
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
Prasoon Kumar
 
PPTX
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
PDF
Building Your First MongoDB Application
Tugdual Grall
 
PPT
9. Document Oriented Databases
Fabio Fumarola
 
PDF
MongoDB.pdf
KuldeepKumar778733
 
KEY
MongoDB
Steven Francia
 
KEY
Mongodb intro
christkv
 
PPTX
Webinar: Building Your First App
MongoDB
 
PPT
Tech Gupshup Meetup On MongoDB - 24/06/2016
Mukesh Tilokani
 
PPT
Introduction to MongoDB
Ravi Teja
 
PPTX
lecture_34e.pptx
janibashashaik25
 
PPTX
Mongo db
Gyanendra Yadav
 
PDF
MongoDB Basics
Sarang Shravagi
 
PPT
MongoDB Pros and Cons
johnrjenson
 
PDF
3-Mongodb and Mapreduce Programming.pdf
MarianJRuben
 
PDF
Mongodb Introduction
Raghvendra Parashar
 
MongoDB
wiTTyMinds1
 
MongoDB DOC v1.5
Tharun Srinivasa
 
Introduction to MongoDB
Mike Dirolf
 
Mongo db eveningschemadesign
MongoDB APAC
 
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
Prasoon Kumar
 
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
Building Your First MongoDB Application
Tugdual Grall
 
9. Document Oriented Databases
Fabio Fumarola
 
MongoDB.pdf
KuldeepKumar778733
 
Mongodb intro
christkv
 
Webinar: Building Your First App
MongoDB
 
Tech Gupshup Meetup On MongoDB - 24/06/2016
Mukesh Tilokani
 
Introduction to MongoDB
Ravi Teja
 
lecture_34e.pptx
janibashashaik25
 
Mongo db
Gyanendra Yadav
 
MongoDB Basics
Sarang Shravagi
 
MongoDB Pros and Cons
johnrjenson
 
3-Mongodb and Mapreduce Programming.pdf
MarianJRuben
 
Mongodb Introduction
Raghvendra Parashar
 
Ad

More from Norberto Leite (20)

PDF
Data Modelling for MongoDB - MongoDB.local Tel Aviv
Norberto Leite
 
PPTX
Avoid Query Pitfalls
Norberto Leite
 
PPTX
MongoDB and Spark
Norberto Leite
 
PDF
Mongo db 3.4 Overview
Norberto Leite
 
PDF
MongoDB Certification Study Group - May 2016
Norberto Leite
 
PDF
Geospatial and MongoDB
Norberto Leite
 
PDF
MongodB Internals
Norberto Leite
 
PDF
MongoDB WiredTiger Internals
Norberto Leite
 
PDF
MongoDB 3.2 Feature Preview
Norberto Leite
 
PDF
Mongodb Spring
Norberto Leite
 
PDF
MongoDB on Azure
Norberto Leite
 
PDF
MongoDB: Agile Combustion Engine
Norberto Leite
 
PDF
MongoDB Capacity Planning
Norberto Leite
 
PDF
Spark and MongoDB
Norberto Leite
 
PDF
Analyse Yourself
Norberto Leite
 
PDF
Python and MongoDB
Norberto Leite
 
PDF
Effectively Deploying MongoDB on AEM
Norberto Leite
 
PPTX
Advanced applications with MongoDB
Norberto Leite
 
PDF
MongoDB and Node.js
Norberto Leite
 
PPTX
MongoDB + Spring
Norberto Leite
 
Data Modelling for MongoDB - MongoDB.local Tel Aviv
Norberto Leite
 
Avoid Query Pitfalls
Norberto Leite
 
MongoDB and Spark
Norberto Leite
 
Mongo db 3.4 Overview
Norberto Leite
 
MongoDB Certification Study Group - May 2016
Norberto Leite
 
Geospatial and MongoDB
Norberto Leite
 
MongodB Internals
Norberto Leite
 
MongoDB WiredTiger Internals
Norberto Leite
 
MongoDB 3.2 Feature Preview
Norberto Leite
 
Mongodb Spring
Norberto Leite
 
MongoDB on Azure
Norberto Leite
 
MongoDB: Agile Combustion Engine
Norberto Leite
 
MongoDB Capacity Planning
Norberto Leite
 
Spark and MongoDB
Norberto Leite
 
Analyse Yourself
Norberto Leite
 
Python and MongoDB
Norberto Leite
 
Effectively Deploying MongoDB on AEM
Norberto Leite
 
Advanced applications with MongoDB
Norberto Leite
 
MongoDB and Node.js
Norberto Leite
 
MongoDB + Spring
Norberto Leite
 

Recently uploaded (20)

PDF
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
PDF
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
PDF
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
PPTX
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
PPTX
Human Resources Information System (HRIS)
Amity University, Patna
 
PPTX
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
PPTX
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
PDF
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
PPTX
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
PDF
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
PPTX
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
PDF
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
PDF
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
PPTX
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
PPTX
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
PDF
Letasoft Sound Booster 1.12.0.538 Crack Download+ Product Key [Latest]
HyperPc soft
 
PPTX
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
PPTX
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
PDF
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
PPTX
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 
Why Businesses Are Switching to Open Source Alternatives to Crystal Reports.pdf
Varsha Nayak
 
Efficient, Automated Claims Processing Software for Insurers
Insurance Tech Services
 
Understanding the Need for Systemic Change in Open Source Through Intersectio...
Imma Valls Bernaus
 
Hardware(Central Processing Unit ) CU and ALU
RizwanaKalsoom2
 
Human Resources Information System (HRIS)
Amity University, Patna
 
Platform for Enterprise Solution - Java EE5
abhishekoza1981
 
Revolutionizing Code Modernization with AI
KrzysztofKkol1
 
Alexander Marshalov - How to use AI Assistants with your Monitoring system Q2...
VictoriaMetrics
 
Writing Better Code - Helping Developers make Decisions.pptx
Lorraine Steyn
 
GridView,Recycler view, API, SQLITE& NetworkRequest.pdf
Nabin Dhakal
 
Comprehensive Guide: Shoviv Exchange to Office 365 Migration Tool 2025
Shoviv Software
 
Unlock Efficiency with Insurance Policy Administration Systems
Insurance Tech Services
 
Thread In Android-Mastering Concurrency for Responsive Apps.pdf
Nabin Dhakal
 
3uTools Full Crack Free Version Download [Latest] 2025
muhammadgurbazkhan
 
MiniTool Power Data Recovery Full Crack Latest 2025
muhammadgurbazkhan
 
Letasoft Sound Booster 1.12.0.538 Crack Download+ Product Key [Latest]
HyperPc soft
 
Equipment Management Software BIS Safety UK.pptx
BIS Safety Software
 
An Introduction to ZAP by Checkmarx - Official Version
Simon Bennetts
 
iTop VPN With Crack Lifetime Activation Key-CODE
utfefguu
 
A Complete Guide to Salesforce SMS Integrations Build Scalable Messaging With...
360 SMS APP
 

Building your first app with MongoDB

  • 2. #mongodbdays @mongodb @nleite #developers Building your first app An introduction to MongoDB Norberto Leite SA, MongoDB
  • 4. Let’s not talk about Fußball!
  • 5. Quick Introduction • Norberto Leite – SA – Madrid, Spain – [email protected] – @nleite
  • 7. Welcome to MongoDB Days Munich! This is YOUR conference!
  • 8. Thanks for being part of the Family!
  • 9. Grab our staff for anything you need!
  • 11. MongoDB is a ___________ database • Document • Open source • High performance • Horizontally scalable • Full featured
  • 12. Document Database • Not for .PDF & .DOC files • A document is essentially an associative array • Document = JSON object • Document = PHP Array • Document = Python Dict • Document = Ruby Hash • etc
  • 13. Open Source • MongoDB is an open source project • On GitHub • Licensed under the AGPL • Started & sponsored by MongoDB Inc (formerly 10gen) • Commercial licenses available • Contributions welcome
  • 14. High Performance • Written in C++ • Extensive use of memory-mapped files i.e. read-through write-through memory caching. • Runs nearly everywhere • Data serialized as BSON (fast parsing) • Full support for primary & secondary indexes • Document model = less work
  • 15. Shard 1 Shard 2 Shard 3 Shard N Horizontally Scalable
  • 17. Full Featured • Ad Hoc queries • Real time aggregation • Rich query capabilities • Strongly consistent • Geospatial features • Support for most programming languages • Flexible schema
  • 18. Setting Expectations • What is MongoDB • How to develop with MongoDB • Scale with MongoDB • Analytics • MMS • Sharding • Setting the correct environment
  • 19. Ready to become a Pro!
  • 21. Running MongoDB $ tar –z xvf mongodb-osx-x86_64-2.6.5.tgz $ cd mongodb-osx-i386-2.4.4/bin $ mkdir –p /data/db $ ./mongod
  • 22. Mongo Shell MacBook-Air-:~ $ mongo MongoDB shell version: 2.6.5 connecting to: test > db.test.insert({text: 'Welcome to MongoDB'}) > db.test.find().pretty() { "_id" : ObjectId("51c34130fbd5d7261b4cdb55"), "text" : "Welcome to MongoDB" }
  • 24. Terminology RDBMS MongoDB Table, View ➜ Collection Row ➜ Document Index ➜ Index Join ➜ Embedded Document Foreign Key ➜ Reference Partition ➜ Shard
  • 27. Let’s Build a Personal Data Hub!
  • 28. First step in any application is Determine your entities
  • 29. Entities in our Data Hub • Accounts • Messages – emails – tweets – comments – streams • Notifications
  • 30. In a relational base app We would start by doing schema design
  • 31. Typical (relational) ERD Messages Email Tweets Facebook messages Alerts Accounts
  • 34. In a MongoDB based app We start building our app and let the schema evolve
  • 35. MongoDB ERD Accounts - account - user - password - refresh_rate - uri Alerts Messages - id - time - account_id - from - to - body - attachments - text - user - time - retweets - subscribers - channel - rate - period - metrics:[] …
  • 38. Switch to Your DB >db test > use datahub switching to db datahub
  • 39. Create our first Document >var account = { "name": "gmail", "credentials": { "user": "[email protected]", "password": "YOU WISH!" }, "smtp": "smpt.gmail.com", "tls": true }
  • 40. Switch to Your DB >db test > use datahub switching to db datahub > db.accounts.insert( account )
  • 41. Insert the Record > db.accounts.insert(account) No collection creation necessary
  • 42. Find One Record > db.accounts.findOne() { "_id": ObjectId("54490561150027cc775b1019"), "name": "gmail", "credentials": { "user": "[email protected]", "password": "YOU WISH!" }, "smtp": "smpt.gmail.com", "tls": true }
  • 43. _id • _id is the primary key in MongoDB • Automatically indexed • Automatically created as an ObjectId if not provided • Any unique immutable value could be used
  • 44. ObjectId • ObjectId is a special 12 byte value • Guaranteed to be unique across your cluster • ObjectId("50804d0bd94ccab2da652599") |----ts-----||---mac---||-pid-||----inc-----| 4 3 2 3
  • 45. Rich Data Types > db.accounts.findOne() { "_id": ObjectId("54490561150027cc775b1019"), "name": "gmail", "credentials": { Strings "user": "[email protected]", "password": "YOU WISH!" }, ”last_access": ISODate("2014-10-30T13:09:36.724Z"), "smtp": "smpt.gmail.com", "tls": true } Date Boolean
  • 46. BSON
  • 47. Inserting Messages (emails, tweets …) > db.messages.insert({ "_id" : ObjectId("54527e08257844421e64623f"), "favorited" : false, "contributors" : null, "truncated" : false, "text" : "converting to #java 8", "in_reply_to_status_id" : null, ”hashtags”: [ "#java", ] … }
  • 48. Inserting Messages (emails, tweets …) > db.messages.insert({ "_id" : ObjectId("54523d2d25784427c6fabce1"), "From" : "[email protected]", "To" : "[email protected]", "Date" : ISODate("2012-08-15T22:32:34Z"), "body" : { "text/plain" : ”Hello Munich, nice to see yalll!" }, "Subject" : ”Live From MongoDB World" })
  • 49. Finding a Message > db.message.find().pretty() { "_id" : ObjectId("54523d2d25784427c6fabce1"), "From" : "[email protected]", "To" : "[email protected]", "Date" : ISODate("2012-08-15T22:32:34Z"), "body" : { "text/plain" : ”Hello Munich, nice to see yalll!" }, "Subject" : ”Live From MongoDB World" } { "_id" : ObjectId("54527e08257844421e64623f"), "favorited" : false, "contributors" : null, "truncated" : false, "text" : "converting to #java 8", "in_reply_to_status_id" : null, ”hashtags”: [ "#java", ] … }
  • 50. Querying An Array > db.article.find({"hashtags":"#java"}).pretty() { "_id" : ObjectId("54527e08257844421e64623f"), "favorited" : false, "contributors" : null, "truncated" : false, "text" : "converting to #java 8, #programing ", "in_reply_to_status_id" : null, ”hashtags”: [ "#java", "#programing"] … } query in JSON
  • 51. Using Update to Add a Comment > db.messages.update({ "_id" : ObjectId("54523d2d25784427c6fabce1") }, {$set: { opened: {date: ISODate("2012-08-15T22:32:34Z"), user: ’Norberto'} } }) > which is a subdocument set new field on the document
  • 52. Post with Comment Attached > db.message.findOne({"_id" : ObjectId("54523d2d25784427c6fabce1")}) { "_id" : ObjectId("54523d2d25784427c6fabce1"), "From" : "[email protected]", "To" : "[email protected]", "Date" : ISODate("2012-08-15T22:32:34Z"), "body" : { "text/plain" : ”Hello Munich, nice to see yalll!" }, "Subject" : ”Live From MongoDB World” "opened" : {"date": ISODate("2012-08-15T22:32:34Z"), "user": ’Norberto'} } Find document by primary key
  • 54. Real applications are not built in the shell
  • 55. MongoDB has native bindings for over 12 languages
  • 56. Morphia MEAN Stack Java Python Perl Ruby Support for the most popular languages and frameworks
  • 58. Great, I’m excited! What’s next?
  • 61. Schema Design, Schema Design, Schema Design, Schema Design!
  • 62. Legacy Migration 1. Copy existing schema & some data to MongoDB 2. Iterate schema design development Measure performance, find bottlenecks, and embed 1. one to one associations first 2. one to many associations next 3. many to many associations 3. Migrate full dataset to new schema New Software Application? Embed by default
  • 63. Embedding over Referencing • Embedding is a bit like pre-joined data – BSON (Binary JSON) document ops are easy for the server • Embed (90/10 following rule of thumb) – When the “one” or “many” objects are viewed in the context of their parent – For performance – For atomicity • Reference – When you need more scaling – For easy consistency with “many to many” associations without duplicated data
  • 64. It’s All About Your Application • Programs+Databases = (Big) Data Applications • Your schema is the impedance matcher – Design choices: normalize/denormalize, reference/embed – Melds programming with MongoDB for best of both – Flexible for development and change • Programs×MongoDB = Great Big Data Applications
  • 65. We've introduced a lot of concepts here
  • 66. IoT
  • 67. MMS @ Scale Easily Best Practices, Automated Cut Management Overhead
  • 69. DevOps @ Provision Upgrade Scale Continuous Backup Point-in-Time Recovery Performance Alerts
  • 70. Wrapping up … • MongoDB is a great Developers Tool • Designed for : • Scalability • Flexibility • Performance • Multipurpose • Great Ecosystem