SlideShare une entreprise Scribd logo
1  sur  53
Télécharger pour lire hors ligne
Building Your First App: An
Introduction to MongoDB
Robert Stam
Software Engineer
MongoDB, Inc.
Great Wide Open Conference
Atlanta, April 2, 2014
What is MongoDB?
3
• Document
• Open source
• High performance
• Horizontally scalable
• Full featured
MongoDB is a __________ database
4
• Not for .PDF & .DOC files
• A document is essentially an associative array
• Document == JSON object
• Document == PHP Array
• Document == Python Dict
• Document == Ruby Hash
• Document == C# BsonDocument object model
• etc
Document Database
5
• MongoDB is an open source project
• On GitHub
• Licensed under the AGPL
• Started & sponsored by MongoDB, Inc
• Commercial licenses available
• Contributions welcome
Open Source
Database Landscape
7
• Written in C++
• Runs nearly everywhere
• Extensive use of memory-mapped files
i.e. read-through write-through memory caching.
• Data serialized as BSON (fast parsing)
• Full support for primary & secondary indexes
• Document model = less work
High Performance
8
• Ad Hoc queries
• Rich query capabilities
• Geospatial features
• Real time aggregation
• Eventually consistent
• Support for many programming languages
• Flexible schema
Full Featured
9
Indexing @
10
Replication @
11
Sharding @
mongodb.org/downloads
Document Database
RDBMS MongoDB
Table, View  Collection
Row  Document
Index  Index
Join  Embedded Document
Foreign Key  Reference
Partition  Shard
Terminology
Typical (relational) ERD
MongoDB ERD
We will build a library management
application
http://www.flickr.com/photos/somegeekintn/3484353131/
First step in any application
Determine your entities
19
• Library Patrons (users)
• Books (card catalog)
• Authors
• Publishers
Library Management Application
Entities
In a relational based app
We would start by doing schema
design
21
• Users
• Books
• Authors
• Publishers
MongoDB Collections
Working with MongoDB
No common programming language
so we are using the MongoDB shell
24
> var user = {
username : "fred.jones",
first_name : "fred",
last_name : "jones"
}
Start with an Object
(or array, hash, dict, etc)
25
> use library
> db.users.insert(user)
Insert the Record
No database or collection creation needed
26
> db.users.findOne()
{
_id : ObjectId("50804d0bd94ccab2da652599"),
username : "fred.jones",
first_name : "fred",
last_name : "jones"
}
Querying for the user
27
• _id is the primary key in MongoDB
• Automatically created as an ObjectId if not
provided
• Any unique immutable value could be used
• Automatically indexed
_id
28
• ObjectId is a special 12 byte value
• Guaranteed to be unique across your cluster
• ObjectId("50804d0bd94ccab2da652599")
ObjectId
Timestamp Machine Pid Increment
50804d0b d94cca b2da 652599
29
> db.author.insert({
first_name : "j.r.r.",
last_name : "tolkien",
bio : "J.R.R. Tolkien (1892.1973), beloved
throughout the world as the creator of The Hobbit and
The Lord of the Rings, was a professor of Anglo-Saxon
at Oxford, a fellow of Pembroke College, and a fellow
of Merton College until his retirement in 1959. His
chief interest was the linguistic aspects of the early
English written tradition, but even as he studied
these classics he was creating a set of his own."
})
Creating an Author
30
> db.books.insert({
title : "fellowship of the ring, the",
author : ObjectID("507ffbb1d94ccab2da652597"),
language : "english",
genre : [ "fantasy", "adventure" ],
publication : {
name : "george allen & unwin",
location : "London",
date : ISODate("1954-07-21T00:00:00Z")
}
})
Creating a Book
31
> db.books.findOne(
{ language : "english" },
{ genre : 1 })
{
"_id" : ObjectID("50804391d94ccab2da652598"),
"genre" : [
"fantasy",
"adventure"
]
}
Multiple Values per Key
32
> db.books.findOne(
{ genre : "fantasy" },
{ title : 1 })
{
"_id" : ObjectID("50804391d94ccab2da652598"),
"title" : "fellowship of the ring, the"
}
Querying for key with
multiple values
33
> db.books.findOne({}, { publication : 1 })
{
"_id" : ObjectID("50804391d94ccab2da652598"),
"publication" : {
"name" : "george allen & unwin",
"location" : "London",
"date" : ISODate("1954-07-21T00:00:00Z")
}
}
Nested Values
34
> db.books.update(
{ _id : ObjectID("50804391d94ccab2da652598") },
{ $set : {
isbn : "0547928211",
pages : 432
}}
)
True agile development.
Simply Change how you work with the
data and the database follows
Update Books
35
> db.books.findOne()
{
"_id" : ObjectId("50804391d94ccab2da652598"),
"author" : ObjectId("507ffbb1d94ccab2da652597"),
"genre" : [ "fantasy", "adventure" ],
"isbn" : "0547928211",
"language" : "english",
"pages" : 432,
"publication" : {
"name" : "george allen & unwin",
"location" : "London",
"date" : ISODate("1954-07-21T00:00:00Z")
},
"title" : "fellowship of the ring, the"
}
Update Books
36
> db.books.ensureIndex({ title : 1 })
> db.books.ensureIndex({ genre : 1 }) // multikey
> db.books.ensureIndex({ "publication.date" : 1 })
Creating Indexes
37
> db.books.findOne({ title : /^fell/ })
{
"_id" : ObjectId("50804391d94ccab2da652598"),
"author" : ObjectId("507ffbb1d94ccab2da652597"),
"genre" : [ "fantasy", "adventure" ],
"isbn" : "0395082544",
"language" : "english",
"pages" : 432,
"publication" : {
"name" : "george allen & unwin",
"location" : "London",
"date" : ISODate("1954-07-21T00:00:00Z")
},
"title" : "fellowship of the ring, the"
}
Querying with RegEx
38
> db.books.insert({
title : "two towers, the",
author : ObjectID("507ffbb1d94ccab2da652597"),
language : "english",
isbn : "034523510X",
genre : [ "fantasy", "adventure" ],
page : 447,
publication : {
name : "george allen & unwin",
location : "London",
date : ISODate("1954-11-11T00:00:00Z")
}
})
Adding a Few More Books
39
> db.books.find(
{ author : ObjectId("507ffbb1d94ccab2da652597") })
.sort({ "publication.date" : -1 })
.limit(1)
{
"_id" : ObjectId("5080d33ed94ccab2da65259d"),
"title" : "return of the king, the",
"author" : ObjectId("507ffbb1d94ccab2da652597"),
"language" : "english",
"isbn" : "0345248295",
"genre" : [ "fantasy", "adventure" ],
"pages" : 544,
"publication" : {
"name" : "george allen & unwin",
"location" : "London",
"date" : ISODate("1955-10-20T00:00:00Z")
}
}
Cursors
40
> var page_num = 3;
> var results_per_page = 10;
> var cursor = db.books.find()
.sort({ publication_date : -1 })
.skip((page_num – 1) * results_per_page)
.limit(results_per_page);
Paging
41
> var book = db.books.findOne(
{ title : "return of the king, the" })
> db.author.findOne({ _id : book.author })
{
"_id" : ObjectId("507ffbb1d94ccab2da652597"),
"first_name" : "j.r.r.",
"last_name" : "tolkien",
"bio" : "J.R.R. Tolkien (1892.1973), beloved throughout
the world as the creator of The Hobbit and The Lord of the
Rings, was a professor of Anglo-Saxon at Oxford, a fellow of
Pembroke College, and a fellow of Merton College until his
retirement in 1959. His chief interest was the linguistic
aspects of the early English written tradition, but even as
he studied these classics he was creating a set of his own."
}
Finding Author by Book
MongoDB Drivers
Real Applications are not built in
the shell
MongoDB has native bindings
for over 12 languages
47
• Official Support for 12 languages
• Community drivers for many more
• Drivers connect applications to mongo servers
• Drivers translate BSON into native types
• mongo shell is not a driver, but works like one in some ways
• Installed using typical means (npm, pecl, gem, pip, nuget)
MongoDB Drivers
48
docs.mongodb.org
49
Online Training at MongoDB University
Questions?
MongoDB World
New York City, June 23-25
Save 25% with Drivers25
Register at world.mongodb.com
See how Cisco, Stripe, Carfax, Expedia and
others are engineering the next generation of
data with MongoDB
MongoDB World
New York City, June 23-25
See what’s next in MongoDB including
• MongoDB 2.6
• Sharding
• Replication
• Aggregation
Save 25% with Drivers25
world.mongodb.com
Software Engineer, MongoDB Inc.
Robert Stam
Thank You

Contenu connexe

Tendances

Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB AppHenrik Ingo
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Javaantoinegirbal
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsMongoDB
 
Back to Basics Webinar 3 - Thinking in Documents
Back to Basics Webinar 3 - Thinking in DocumentsBack to Basics Webinar 3 - Thinking in Documents
Back to Basics Webinar 3 - Thinking in DocumentsJoe Drumgoole
 
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 ApplicationMongoDB
 
Back to Basics Webinar 3: Schema Design Thinking in Documents
 Back to Basics Webinar 3: Schema Design Thinking in Documents Back to Basics Webinar 3: Schema Design Thinking in Documents
Back to Basics Webinar 3: Schema Design Thinking in DocumentsMongoDB
 
Data Modeling for the Real World
Data Modeling for the Real WorldData Modeling for the Real World
Data Modeling for the Real WorldMike Friedman
 
Back to Basics Webinar 1 - Introduction to NoSQL
Back to Basics Webinar 1 - Introduction to NoSQLBack to Basics Webinar 1 - Introduction to NoSQL
Back to Basics Webinar 1 - Introduction to NoSQLJoe Drumgoole
 
Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013Steven Francia
 
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...MongoDB
 
Webinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsWebinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsMongoDB
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesBack to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesMongoDB
 
Redis data modeling examples
Redis data modeling examplesRedis data modeling examples
Redis data modeling examplesTerry Cho
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDBNosh Petigara
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMike Friedman
 
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 presentationMurat Çakal
 

Tendances (19)

Building Your First MongoDB App
Building Your First MongoDB AppBuilding Your First MongoDB App
Building Your First MongoDB App
 
Building a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and JavaBuilding a Scalable Inbox System with MongoDB and Java
Building a Scalable Inbox System with MongoDB and Java
 
Webinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in DocumentsWebinar: Back to Basics: Thinking in Documents
Webinar: Back to Basics: Thinking in Documents
 
Back to Basics Webinar 3 - Thinking in Documents
Back to Basics Webinar 3 - Thinking in DocumentsBack to Basics Webinar 3 - Thinking in Documents
Back to Basics Webinar 3 - Thinking in Documents
 
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 3: Schema Design Thinking in Documents
 Back to Basics Webinar 3: Schema Design Thinking in Documents Back to Basics Webinar 3: Schema Design Thinking in Documents
Back to Basics Webinar 3: Schema Design Thinking in Documents
 
Data Modeling for the Real World
Data Modeling for the Real WorldData Modeling for the Real World
Data Modeling for the Real World
 
Back to Basics Webinar 1 - Introduction to NoSQL
Back to Basics Webinar 1 - Introduction to NoSQLBack to Basics Webinar 1 - Introduction to NoSQL
Back to Basics Webinar 1 - Introduction to NoSQL
 
Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013Build your first MongoDB App in Ruby @ StrangeLoop 2013
Build your first MongoDB App in Ruby @ StrangeLoop 2013
 
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
MongoDB San Francisco 2013: Data Modeling Examples From the Real World presen...
 
MongoDB
MongoDBMongoDB
MongoDB
 
Webinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to BasicsWebinar: Getting Started with MongoDB - Back to Basics
Webinar: Getting Started with MongoDB - Back to Basics
 
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial IndexesBack to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
Back to Basics Webinar 4: Advanced Indexing, Text and Geospatial Indexes
 
Latinoware
LatinowareLatinoware
Latinoware
 
Redis data modeling examples
Redis data modeling examplesRedis data modeling examples
Redis data modeling examples
 
Introduction to MongoDB
Introduction to MongoDBIntroduction to MongoDB
Introduction to MongoDB
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
 
Indexing
IndexingIndexing
Indexing
 
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
 

Similaire à Building Your First App: An Introduction to MongoDB

Introduction to MongoDB and Hadoop
Introduction to MongoDB and HadoopIntroduction to MongoDB and Hadoop
Introduction to MongoDB and HadoopSteven Francia
 
buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf
buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdfbuildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf
buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdflallababa
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDBJeremy Taylor
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDBMongoDB
 
Agile Schema Design: An introduction to MongoDB
Agile Schema Design: An introduction to MongoDBAgile Schema Design: An introduction to MongoDB
Agile Schema Design: An introduction to MongoDBStennie Steneker
 
Building Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDBBuilding Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDBMongoDB
 
Webinar: Schema Design
Webinar: Schema DesignWebinar: Schema Design
Webinar: Schema DesignMongoDB
 
Webinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB AppWebinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB AppMongoDB
 
運用 Exposed 管理及操作資料庫
運用 Exposed 管理及操作資料庫運用 Exposed 管理及操作資料庫
運用 Exposed 管理及操作資料庫Shengyou Fan
 
Schema design
Schema designSchema design
Schema designchristkv
 
Data Modeling Examples from the Real World
Data Modeling Examples from the Real WorldData Modeling Examples from the Real World
Data Modeling Examples from the Real WorldMongoDB
 
Choosing a Shard key
Choosing a Shard keyChoosing a Shard key
Choosing a Shard keyMongoDB
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDBMongoDB
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)Uwe Printz
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDBrogerbodamer
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesLewis Lin 🦊
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data ModelingDATAVERSITY
 
Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDBMongoDB
 
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 TeamsMongoDB
 

Similaire à Building Your First App: An Introduction to MongoDB (20)

Introduction to MongoDB and Hadoop
Introduction to MongoDB and HadoopIntroduction to MongoDB and Hadoop
Introduction to MongoDB and Hadoop
 
buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf
buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdfbuildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf
buildyourfirstmongodbappberlin2013thomas-130313104259-phpapp02.pdf
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
Building Your First App with MongoDB
Building Your First App with MongoDBBuilding Your First App with MongoDB
Building Your First App with MongoDB
 
Agile Schema Design: An introduction to MongoDB
Agile Schema Design: An introduction to MongoDBAgile Schema Design: An introduction to MongoDB
Agile Schema Design: An introduction to MongoDB
 
Building Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDBBuilding Your First App: An Introduction to MongoDB
Building Your First App: An Introduction to MongoDB
 
Webinar: Schema Design
Webinar: Schema DesignWebinar: Schema Design
Webinar: Schema Design
 
MongoDB at GUL
MongoDB at GULMongoDB at GUL
MongoDB at GUL
 
Webinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB AppWebinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB App
 
運用 Exposed 管理及操作資料庫
運用 Exposed 管理及操作資料庫運用 Exposed 管理及操作資料庫
運用 Exposed 管理及操作資料庫
 
Schema design
Schema designSchema design
Schema design
 
Data Modeling Examples from the Real World
Data Modeling Examples from the Real WorldData Modeling Examples from the Real World
Data Modeling Examples from the Real World
 
Choosing a Shard key
Choosing a Shard keyChoosing a Shard key
Choosing a Shard key
 
Managing Social Content with MongoDB
Managing Social Content with MongoDBManaging Social Content with MongoDB
Managing Social Content with MongoDB
 
MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)MongoDB for Coder Training (Coding Serbia 2013)
MongoDB for Coder Training (Coding Serbia 2013)
 
Schema Design with MongoDB
Schema Design with MongoDBSchema Design with MongoDB
Schema Design with MongoDB
 
MongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World ExamplesMongoDB Schema Design: Four Real-World Examples
MongoDB Schema Design: Four Real-World Examples
 
10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling10gen Presents Schema Design and Data Modeling
10gen Presents Schema Design and Data Modeling
 
Building Your First Application with MongoDB
Building Your First Application with MongoDBBuilding Your First Application with MongoDB
Building Your First Application with MongoDB
 
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
 

Plus de Great Wide Open

The Little Meetup That Could
The Little Meetup That CouldThe Little Meetup That Could
The Little Meetup That CouldGreat Wide Open
 
Lightning Talk - 5 Hacks to Getting the Job of Your Dreams
Lightning Talk - 5 Hacks to Getting the Job of Your DreamsLightning Talk - 5 Hacks to Getting the Job of Your Dreams
Lightning Talk - 5 Hacks to Getting the Job of Your DreamsGreat Wide Open
 
Breaking Free from Proprietary Gravitational Pull
Breaking Free from Proprietary Gravitational PullBreaking Free from Proprietary Gravitational Pull
Breaking Free from Proprietary Gravitational PullGreat Wide Open
 
Dealing with Unstructured Data: Scaling to Infinity
Dealing with Unstructured Data: Scaling to InfinityDealing with Unstructured Data: Scaling to Infinity
Dealing with Unstructured Data: Scaling to InfinityGreat Wide Open
 
You Don't Know Node: Quick Intro to 6 Core Features
You Don't Know Node: Quick Intro to 6 Core FeaturesYou Don't Know Node: Quick Intro to 6 Core Features
You Don't Know Node: Quick Intro to 6 Core FeaturesGreat Wide Open
 
Using Cryptography Properly in Applications
Using Cryptography Properly in ApplicationsUsing Cryptography Properly in Applications
Using Cryptography Properly in ApplicationsGreat Wide Open
 
Lightning Talk - Getting Students Involved In Open Source
Lightning Talk - Getting Students Involved In Open SourceLightning Talk - Getting Students Involved In Open Source
Lightning Talk - Getting Students Involved In Open SourceGreat Wide Open
 
You have Selenium... Now what?
You have Selenium... Now what?You have Selenium... Now what?
You have Selenium... Now what?Great Wide Open
 
How Constraints Cultivate Growth
How Constraints Cultivate GrowthHow Constraints Cultivate Growth
How Constraints Cultivate GrowthGreat Wide Open
 
Troubleshooting Hadoop: Distributed Debugging
Troubleshooting Hadoop: Distributed DebuggingTroubleshooting Hadoop: Distributed Debugging
Troubleshooting Hadoop: Distributed DebuggingGreat Wide Open
 
The Current Messaging Landscape
The Current Messaging LandscapeThe Current Messaging Landscape
The Current Messaging LandscapeGreat Wide Open
 
Understanding Open Source Class 101
Understanding Open Source Class 101Understanding Open Source Class 101
Understanding Open Source Class 101Great Wide Open
 
Elasticsearch for SQL Users
Elasticsearch for SQL UsersElasticsearch for SQL Users
Elasticsearch for SQL UsersGreat Wide Open
 

Plus de Great Wide Open (20)

The Little Meetup That Could
The Little Meetup That CouldThe Little Meetup That Could
The Little Meetup That Could
 
Lightning Talk - 5 Hacks to Getting the Job of Your Dreams
Lightning Talk - 5 Hacks to Getting the Job of Your DreamsLightning Talk - 5 Hacks to Getting the Job of Your Dreams
Lightning Talk - 5 Hacks to Getting the Job of Your Dreams
 
Breaking Free from Proprietary Gravitational Pull
Breaking Free from Proprietary Gravitational PullBreaking Free from Proprietary Gravitational Pull
Breaking Free from Proprietary Gravitational Pull
 
Dealing with Unstructured Data: Scaling to Infinity
Dealing with Unstructured Data: Scaling to InfinityDealing with Unstructured Data: Scaling to Infinity
Dealing with Unstructured Data: Scaling to Infinity
 
You Don't Know Node: Quick Intro to 6 Core Features
You Don't Know Node: Quick Intro to 6 Core FeaturesYou Don't Know Node: Quick Intro to 6 Core Features
You Don't Know Node: Quick Intro to 6 Core Features
 
Hidden Features in HTTP
Hidden Features in HTTPHidden Features in HTTP
Hidden Features in HTTP
 
Using Cryptography Properly in Applications
Using Cryptography Properly in ApplicationsUsing Cryptography Properly in Applications
Using Cryptography Properly in Applications
 
Lightning Talk - Getting Students Involved In Open Source
Lightning Talk - Getting Students Involved In Open SourceLightning Talk - Getting Students Involved In Open Source
Lightning Talk - Getting Students Involved In Open Source
 
You have Selenium... Now what?
You have Selenium... Now what?You have Selenium... Now what?
You have Selenium... Now what?
 
How Constraints Cultivate Growth
How Constraints Cultivate GrowthHow Constraints Cultivate Growth
How Constraints Cultivate Growth
 
Inner Source 101
Inner Source 101Inner Source 101
Inner Source 101
 
Running MySQL on Linux
Running MySQL on LinuxRunning MySQL on Linux
Running MySQL on Linux
 
Search is the new UI
Search is the new UISearch is the new UI
Search is the new UI
 
Troubleshooting Hadoop: Distributed Debugging
Troubleshooting Hadoop: Distributed DebuggingTroubleshooting Hadoop: Distributed Debugging
Troubleshooting Hadoop: Distributed Debugging
 
The Current Messaging Landscape
The Current Messaging LandscapeThe Current Messaging Landscape
The Current Messaging Landscape
 
Apache httpd v2.4
Apache httpd v2.4Apache httpd v2.4
Apache httpd v2.4
 
Understanding Open Source Class 101
Understanding Open Source Class 101Understanding Open Source Class 101
Understanding Open Source Class 101
 
Thinking in Git
Thinking in GitThinking in Git
Thinking in Git
 
Antifragile Design
Antifragile DesignAntifragile Design
Antifragile Design
 
Elasticsearch for SQL Users
Elasticsearch for SQL UsersElasticsearch for SQL Users
Elasticsearch for SQL Users
 

Dernier

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demoHarshalMandlekar2
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr BaganFwdays
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embeddingZilliz
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 

Dernier (20)

The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
Sample pptx for embedding into website for demo
Sample pptx for embedding into website for demoSample pptx for embedding into website for demo
Sample pptx for embedding into website for demo
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan"ML in Production",Oleksandr Bagan
"ML in Production",Oleksandr Bagan
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Training state-of-the-art general text embedding
Training state-of-the-art general text embeddingTraining state-of-the-art general text embedding
Training state-of-the-art general text embedding
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 

Building Your First App: An Introduction to MongoDB

  • 1. Building Your First App: An Introduction to MongoDB Robert Stam Software Engineer MongoDB, Inc. Great Wide Open Conference Atlanta, April 2, 2014
  • 3. 3 • Document • Open source • High performance • Horizontally scalable • Full featured MongoDB is a __________ database
  • 4. 4 • Not for .PDF & .DOC files • A document is essentially an associative array • Document == JSON object • Document == PHP Array • Document == Python Dict • Document == Ruby Hash • Document == C# BsonDocument object model • etc Document Database
  • 5. 5 • MongoDB is an open source project • On GitHub • Licensed under the AGPL • Started & sponsored by MongoDB, Inc • Commercial licenses available • Contributions welcome Open Source
  • 7. 7 • Written in C++ • Runs nearly everywhere • Extensive use of memory-mapped files i.e. read-through write-through memory caching. • Data serialized as BSON (fast parsing) • Full support for primary & secondary indexes • Document model = less work High Performance
  • 8. 8 • Ad Hoc queries • Rich query capabilities • Geospatial features • Real time aggregation • Eventually consistent • Support for many programming languages • Flexible schema Full Featured
  • 14. RDBMS MongoDB Table, View  Collection Row  Document Index  Index Join  Embedded Document Foreign Key  Reference Partition  Shard Terminology
  • 17. We will build a library management application http://www.flickr.com/photos/somegeekintn/3484353131/
  • 18. First step in any application Determine your entities
  • 19. 19 • Library Patrons (users) • Books (card catalog) • Authors • Publishers Library Management Application Entities
  • 20. In a relational based app We would start by doing schema design
  • 21. 21 • Users • Books • Authors • Publishers MongoDB Collections
  • 23. No common programming language so we are using the MongoDB shell
  • 24. 24 > var user = { username : "fred.jones", first_name : "fred", last_name : "jones" } Start with an Object (or array, hash, dict, etc)
  • 25. 25 > use library > db.users.insert(user) Insert the Record No database or collection creation needed
  • 26. 26 > db.users.findOne() { _id : ObjectId("50804d0bd94ccab2da652599"), username : "fred.jones", first_name : "fred", last_name : "jones" } Querying for the user
  • 27. 27 • _id is the primary key in MongoDB • Automatically created as an ObjectId if not provided • Any unique immutable value could be used • Automatically indexed _id
  • 28. 28 • ObjectId is a special 12 byte value • Guaranteed to be unique across your cluster • ObjectId("50804d0bd94ccab2da652599") ObjectId Timestamp Machine Pid Increment 50804d0b d94cca b2da 652599
  • 29. 29 > db.author.insert({ first_name : "j.r.r.", last_name : "tolkien", bio : "J.R.R. Tolkien (1892.1973), beloved throughout the world as the creator of The Hobbit and The Lord of the Rings, was a professor of Anglo-Saxon at Oxford, a fellow of Pembroke College, and a fellow of Merton College until his retirement in 1959. His chief interest was the linguistic aspects of the early English written tradition, but even as he studied these classics he was creating a set of his own." }) Creating an Author
  • 30. 30 > db.books.insert({ title : "fellowship of the ring, the", author : ObjectID("507ffbb1d94ccab2da652597"), language : "english", genre : [ "fantasy", "adventure" ], publication : { name : "george allen & unwin", location : "London", date : ISODate("1954-07-21T00:00:00Z") } }) Creating a Book
  • 31. 31 > db.books.findOne( { language : "english" }, { genre : 1 }) { "_id" : ObjectID("50804391d94ccab2da652598"), "genre" : [ "fantasy", "adventure" ] } Multiple Values per Key
  • 32. 32 > db.books.findOne( { genre : "fantasy" }, { title : 1 }) { "_id" : ObjectID("50804391d94ccab2da652598"), "title" : "fellowship of the ring, the" } Querying for key with multiple values
  • 33. 33 > db.books.findOne({}, { publication : 1 }) { "_id" : ObjectID("50804391d94ccab2da652598"), "publication" : { "name" : "george allen & unwin", "location" : "London", "date" : ISODate("1954-07-21T00:00:00Z") } } Nested Values
  • 34. 34 > db.books.update( { _id : ObjectID("50804391d94ccab2da652598") }, { $set : { isbn : "0547928211", pages : 432 }} ) True agile development. Simply Change how you work with the data and the database follows Update Books
  • 35. 35 > db.books.findOne() { "_id" : ObjectId("50804391d94ccab2da652598"), "author" : ObjectId("507ffbb1d94ccab2da652597"), "genre" : [ "fantasy", "adventure" ], "isbn" : "0547928211", "language" : "english", "pages" : 432, "publication" : { "name" : "george allen & unwin", "location" : "London", "date" : ISODate("1954-07-21T00:00:00Z") }, "title" : "fellowship of the ring, the" } Update Books
  • 36. 36 > db.books.ensureIndex({ title : 1 }) > db.books.ensureIndex({ genre : 1 }) // multikey > db.books.ensureIndex({ "publication.date" : 1 }) Creating Indexes
  • 37. 37 > db.books.findOne({ title : /^fell/ }) { "_id" : ObjectId("50804391d94ccab2da652598"), "author" : ObjectId("507ffbb1d94ccab2da652597"), "genre" : [ "fantasy", "adventure" ], "isbn" : "0395082544", "language" : "english", "pages" : 432, "publication" : { "name" : "george allen & unwin", "location" : "London", "date" : ISODate("1954-07-21T00:00:00Z") }, "title" : "fellowship of the ring, the" } Querying with RegEx
  • 38. 38 > db.books.insert({ title : "two towers, the", author : ObjectID("507ffbb1d94ccab2da652597"), language : "english", isbn : "034523510X", genre : [ "fantasy", "adventure" ], page : 447, publication : { name : "george allen & unwin", location : "London", date : ISODate("1954-11-11T00:00:00Z") } }) Adding a Few More Books
  • 39. 39 > db.books.find( { author : ObjectId("507ffbb1d94ccab2da652597") }) .sort({ "publication.date" : -1 }) .limit(1) { "_id" : ObjectId("5080d33ed94ccab2da65259d"), "title" : "return of the king, the", "author" : ObjectId("507ffbb1d94ccab2da652597"), "language" : "english", "isbn" : "0345248295", "genre" : [ "fantasy", "adventure" ], "pages" : 544, "publication" : { "name" : "george allen & unwin", "location" : "London", "date" : ISODate("1955-10-20T00:00:00Z") } } Cursors
  • 40. 40 > var page_num = 3; > var results_per_page = 10; > var cursor = db.books.find() .sort({ publication_date : -1 }) .skip((page_num – 1) * results_per_page) .limit(results_per_page); Paging
  • 41. 41 > var book = db.books.findOne( { title : "return of the king, the" }) > db.author.findOne({ _id : book.author }) { "_id" : ObjectId("507ffbb1d94ccab2da652597"), "first_name" : "j.r.r.", "last_name" : "tolkien", "bio" : "J.R.R. Tolkien (1892.1973), beloved throughout the world as the creator of The Hobbit and The Lord of the Rings, was a professor of Anglo-Saxon at Oxford, a fellow of Pembroke College, and a fellow of Merton College until his retirement in 1959. His chief interest was the linguistic aspects of the early English written tradition, but even as he studied these classics he was creating a set of his own." } Finding Author by Book
  • 43. Real Applications are not built in the shell
  • 44. MongoDB has native bindings for over 12 languages
  • 45.
  • 46.
  • 47. 47 • Official Support for 12 languages • Community drivers for many more • Drivers connect applications to mongo servers • Drivers translate BSON into native types • mongo shell is not a driver, but works like one in some ways • Installed using typical means (npm, pecl, gem, pip, nuget) MongoDB Drivers
  • 49. 49 Online Training at MongoDB University
  • 51. MongoDB World New York City, June 23-25 Save 25% with Drivers25 Register at world.mongodb.com See how Cisco, Stripe, Carfax, Expedia and others are engineering the next generation of data with MongoDB
  • 52. MongoDB World New York City, June 23-25 See what’s next in MongoDB including • MongoDB 2.6 • Sharding • Replication • Aggregation Save 25% with Drivers25 world.mongodb.com
  • 53. Software Engineer, MongoDB Inc. Robert Stam Thank You