SlideShare a Scribd company logo
Dev Jumpstart: Build Your First App with MongoDB
Building Your First App With 
MongoDB 
Andrew Erlichson, 
Vice President of Engineering 
Developer Experience
What is MongoDB
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
Terminology 
RDBMS MongoDB 
Table, View ➜ Collection 
Row ➜ Document 
Index ➜ Index 
Join ➜ Embedded Document 
Foreign Key ➜ Reference 
Partition ➜ Shard
Open Source 
• MongoDB is an open source project 
• On GitHub 
• Licensed under the AGPL 
• Started & sponsored by MongoDB, Inc. 
• Commercial licenses available 
• Contributions welcome
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
http://www.mongodb.org/downloads
Running MongoDB 
$ tar xvf mongodb-osx-x86_64-2.6.5.tgz 
$ cd mongodb-osx-x86_64-2.6.5/bin 
$ mkdir –p /data/db 
$ ./mongod
Andrews-Air:MongoDB-SF2014 aje$ mongo 
MongoDB shell version: 2.6.5 
connecting to: test 
Server has startup warnings: 
2014-12-01T23:29:15.317-0500 [initandlisten] 
2014-12-01T23:29:15.317-0500 [initandlisten] ** WARNING: soft rlimits too low. 
Number of files is 256, should be at least 1000 
aje_air:PRIMARY> db.names.insert({'fullname':'Andrew Erlichson'}); 
WriteResult({ "nInserted" : 1 }) 
aje_air:PRIMARY> db.names.findOne(); 
{ 
"_id" : ObjectId("547dd9a0f907ebca54d1d994"), 
"fullname" : "Andrew Erlichson" 
} 
aje_air:PRIMARY> 
Mongo Shell
Web Demo 
• MongoDB 
• Python 
• Bottle web framework 
• Pymongo
hello.py 
from pymongo import MongoClient 
from bottle import route, run, template 
@route('/') 
def index(): 
collection = db.names 
doc = collection.find_one() 
return "Hello " + doc['fullname'] 
client = MongoClient('localhost', 27017) 
db = client.test 
run(host='localhost', port=8080)
@route('/') 
def index(): 
hello.py 
collection = db.names 
doc = collection.find_one() 
return "Hello " + doc['fullname'] 
client = MongoClient('localhost', 27017) 
db = client.test 
run(host='localhost', port=8080) 
Import the modules needed for 
Pymongo and the bottle web 
framework
hello.py 
from pymongo import MongoClient 
from bottle import route, run, template 
@route('/') 
def index(): 
collection = db.names 
doc = collection.find_one() 
return "Hello " + doc['fullname'] 
run(host='localhost', port=8080) 
Connect to the MongoDB 
Database on Localhost and 
use the “test” database
hello.py 
from pymongo import MongoClient 
from bottle import route, run, template 
client = MongoClient('localhost', 27017) 
db = client.test 
run(host='localhost', port=8080) 
Define a handler that runs when 
user hits the root of our web 
servers. That handler does a single 
query to the database and prints 
back to the web browser
hello.py 
from pymongo import MongoClient 
from bottle import route, run, template 
@route('/') 
def index(): 
collection = db.names 
doc = collection.find_one() 
return "Hello " + doc['fullname'] 
client = MongoClient('localhost', 27017) 
db = client.test 
Start the webserver on 
locahost, listening on 
port 8080
Let’s Build a Blog
Determine Your Entities 
First Step In Your App
Entities in our Blogging System 
• Users (post authors) 
• Posts 
• Comments 
• Tags
We Would Start By Doing Schema 
Design 
In a relational based app
Typical (relational) ERD 
tags 
tag_id 
tag 
post_id 
post_title 
body 
post_date 
post_author_uid 
post_id 
comment_id 
comment 
author_name 
comment_date 
author_email 
users 
uid 
username 
password 
Email 
post_id 
tag_id 
posts comments 
post_tags
We Start By Building Our App 
And Let The Schema Evolve
MongoDB ERD 
Posts 
title 
body 
date 
username 
[ ] comments 
[ ] tags 
Users 
Username 
password 
email
Working in The Shell
user = { 
_id: ’erlichson', 
"password" : 
"a7cf1c46861b140894e1371a0eb6cd6791ca2e339f1a 
8d83a1846f6c81141dec,zYJue", 
, 
email: ’andrew@mongodb.com', 
} 
Start with an object 
(or array, hash, dict, etc)
Insert the record 
> db.users.insert(user) 
No collection creation needed
> db.users.findOne() 
{ 
"_id" : "erlichson", 
"password" : 
"a7cf1c46861b140894e1371a0eb6cd6791ca2e339f1a8d83a184 
6f6c81141dec,zYJue", 
"email" : “aje@10gen.com” 
} 
Querying for the user
> db.posts.insert({ 
title: ‘Hello World’, 
body: ‘This is my first blog post’, 
date: new Date(‘2013-06-20’), 
username: ‘erlichson’, 
tags: [‘adventure’, ‘mongodb’], 
comments: [] 
}) 
Creating a blog post
 db.posts.find().pretty() 
"_id" : ObjectId("51c3bafafbd5d7261b4cdb5a"), 
"title" : "Hello World", 
"body" : "This is my first blog post", 
"date" : ISODate("2013-06-20T00:00:00Z"), 
"username" : "erlichson", 
"tags" : [ 
"adventure", 
"mongodb" 
], 
"comments" : [ ] 
} 
Finding the Post
> db.posts.find({tags:'adventure'}).pretty() 
{ 
"_id" : ObjectId("51c3bcddfbd5d7261b4cdb5b"), 
"title" : "Hello World", 
"body" : "This is my first blog post", 
"date" : ISODate("2013-06-20T00:00:00Z"), 
"username" : "erlichson", 
"tags" : [ 
"adventure", 
"mongodb" 
], 
"comments" : [ ] 
} 
Querying an Array
> db.posts.update({_id: 
new ObjectId("51c3bcddfbd5d7261b4cdb5b")}, 
{$push:{comments: 
{name: 'Steve Blank', comment: 'Awesome Post'}}}) 
> 
Using Update to Add a 
Comment
> {_id: 
new ObjectId("51c3bcddfbd5d7261b4cdb5b")}, 
> 
Using Update to Add a 
Comment 
Predicate of the query. Specifies 
which document to update
> db.posts.update({_id: 
new ObjectId("51c3bcddfbd5d7261b4cdb5b")}, 
{$push:{comments: 
{name: 'Steve Blank', comment: 'Awesome Post'}}}) 
> 
Using Update to Add a 
Comment 
“push” a new document under 
the “comments” array
> db.posts.findOne({_id: new ObjectId("51c3bcddfbd5d7261b4cdb5b")}) 
{ 
"_id" : ObjectId("51c3bcddfbd5d7261b4cdb5b"), 
"body" : "This is my first blog post", 
"comments" : [ 
{ 
"name" : "Steve Blank", 
"comment" : "Awesome Post" 
} 
], 
"date" : ISODate("2013-06-20T00:00:00Z"), 
"tags" : [ 
"adventure", 
"mongodb" 
], 
"title" : "Hello World", 
"username" : "erlichson" 
} 
Post with Comment Attached
Completed Blog Demo 
• Python 
• Bottle.py 
• Pymongo 
• Features Supported 
– Creating users 
– Logging in 
– Logging out 
– Displaying Content 
– Adding a new Blog Post
MongoDB Drivers
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
http://docs.mongodb.org/ecosystem/drivers/
Next Steps
http://docs.mongodb.org/manual/
MongoDB University
Data Modeling Deep Dive 
2pm in Robertson Auditorium 1
Replication Internals 
2pm in Fischer Banquet Room West
MongoDB Performance Debugging 
11:40am in Robertson Auditorium 3
How to Achieve Scale 
11:40am in Robertson Auditorium 2
Dev Jumpstart: Build Your First App with MongoDB

More Related Content

What's hot (20)

Introduction to the new official C# Driver developed by 10gen
Introduction to the new official C# Driver developed by 10gen
MongoDB
 
Academy PRO: Elasticsearch. Data management
Academy PRO: Elasticsearch. Data management
Binary Studio
 
Everybody Loves AFNetworking ... and So Can you!
Everybody Loves AFNetworking ... and So Can you!
jeffsoto
 
Working with AFNetworking
Working with AFNetworking
waynehartman
 
Javascript call ObjC
Javascript call ObjC
Lin Luxiang
 
Mongo db for c# developers
Mongo db for c# developers
Simon Elliston Ball
 
async/await in Swift
async/await in Swift
Peter Friese
 
2013-08-08 | Mantle (Cocoaheads Vienna)
2013-08-08 | Mantle (Cocoaheads Vienna)
Dominik Gruber
 
The Ring programming language version 1.10 book - Part 50 of 212
The Ring programming language version 1.10 book - Part 50 of 212
Mahmoud Samir Fayed
 
FiiPractic 2015 - Adroid Pro - Day 3 - API Day
FiiPractic 2015 - Adroid Pro - Day 3 - API Day
Diaconu Andrei-Tudor
 
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK - Nicola Iarocci - Co...
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK - Nicola Iarocci - Co...
Codemotion
 
Webエンジニアから見たiOS5
Webエンジニアから見たiOS5
Satoshi Asano
 
Retrofit Android by Chris Ollenburg
Retrofit Android by Chris Ollenburg
Trey Robinson
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
mfrancis
 
Hidden Treasures in Project Wonder
Hidden Treasures in Project Wonder
WO Community
 
REST with Eve and Python
REST with Eve and Python
PiXeL16
 
Building APIs with MVC 6 and OAuth
Building APIs with MVC 6 and OAuth
Filip Ekberg
 
Leveraging parse.com for Speedy Development
Leveraging parse.com for Speedy Development
Andrew Kozlik
 
Node.js and Parse
Node.js and Parse
Nicholas McClay
 
Fun with Python
Fun with Python
Narong Intiruk
 
Introduction to the new official C# Driver developed by 10gen
Introduction to the new official C# Driver developed by 10gen
MongoDB
 
Academy PRO: Elasticsearch. Data management
Academy PRO: Elasticsearch. Data management
Binary Studio
 
Everybody Loves AFNetworking ... and So Can you!
Everybody Loves AFNetworking ... and So Can you!
jeffsoto
 
Working with AFNetworking
Working with AFNetworking
waynehartman
 
Javascript call ObjC
Javascript call ObjC
Lin Luxiang
 
async/await in Swift
async/await in Swift
Peter Friese
 
2013-08-08 | Mantle (Cocoaheads Vienna)
2013-08-08 | Mantle (Cocoaheads Vienna)
Dominik Gruber
 
The Ring programming language version 1.10 book - Part 50 of 212
The Ring programming language version 1.10 book - Part 50 of 212
Mahmoud Samir Fayed
 
FiiPractic 2015 - Adroid Pro - Day 3 - API Day
FiiPractic 2015 - Adroid Pro - Day 3 - API Day
Diaconu Andrei-Tudor
 
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK - Nicola Iarocci - Co...
RESTFUL SERVICES MADE EASY: THE EVE REST API FRAMEWORK - Nicola Iarocci - Co...
Codemotion
 
Webエンジニアから見たiOS5
Webエンジニアから見たiOS5
Satoshi Asano
 
Retrofit Android by Chris Ollenburg
Retrofit Android by Chris Ollenburg
Trey Robinson
 
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
OSGi and Spring Data for simple (Web) Application Development - Christian Bar...
mfrancis
 
Hidden Treasures in Project Wonder
Hidden Treasures in Project Wonder
WO Community
 
REST with Eve and Python
REST with Eve and Python
PiXeL16
 
Building APIs with MVC 6 and OAuth
Building APIs with MVC 6 and OAuth
Filip Ekberg
 
Leveraging parse.com for Speedy Development
Leveraging parse.com for Speedy Development
Andrew Kozlik
 

Similar to Dev Jumpstart: Build Your First App with MongoDB (20)

Webinar: Building Your First App
Webinar: Building Your First App
MongoDB
 
Webinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB App
MongoDB
 
Building Your First MongoDB App
Building Your First MongoDB App
Henrik Ingo
 
Building your first app with mongo db
Building your first app with mongo db
MongoDB
 
Building your first app with MongoDB
Building your first app with MongoDB
Norberto Leite
 
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
Prasoon Kumar
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
Building Your First App with Shawn Mcarthy
Building Your First App with Shawn Mcarthy
MongoDB
 
Building Your First MongoDB Application
Building Your First MongoDB Application
Tugdual Grall
 
Introduction to MongoDB
Introduction to MongoDB
Hossein Boustani
 
MongoDB
MongoDB
wiTTyMinds1
 
Mongodb intro
Mongodb intro
christkv
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
NETWAYS
 
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009
Mike Dirolf
 
Back to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDB
MongoDB
 
Mongo learning series
Mongo learning series
Prashanth Panduranga
 
Tech Gupshup Meetup On MongoDB - 24/06/2016
Tech Gupshup Meetup On MongoDB - 24/06/2016
Mukesh Tilokani
 
Mongo db eveningschemadesign
Mongo db eveningschemadesign
MongoDB APAC
 
The emerging world of mongo db csp
The emerging world of mongo db csp
Carlos Sánchez Pérez
 
Python mongo db-training-europython-2011
Python mongo db-training-europython-2011
Andreas Jung
 
Webinar: Building Your First App
Webinar: Building Your First App
MongoDB
 
Webinar: Building Your First MongoDB App
Webinar: Building Your First MongoDB App
MongoDB
 
Building Your First MongoDB App
Building Your First MongoDB App
Henrik Ingo
 
Building your first app with mongo db
Building your first app with mongo db
MongoDB
 
Building your first app with MongoDB
Building your first app with MongoDB
Norberto Leite
 
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
MongoDB Introduction talk at Dr Dobbs Conference, MongoDB Evenings at Bangalo...
Prasoon Kumar
 
Dev Jumpstart: Build Your First App with MongoDB
Dev Jumpstart: Build Your First App with MongoDB
MongoDB
 
Building Your First App with Shawn Mcarthy
Building Your First App with Shawn Mcarthy
MongoDB
 
Building Your First MongoDB Application
Building Your First MongoDB Application
Tugdual Grall
 
Mongodb intro
Mongodb intro
christkv
 
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
OSDC 2012 | Building a first application on MongoDB by Ross Lawley
NETWAYS
 
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009
Mike Dirolf
 
Back to Basics 2017: Mí primera aplicación MongoDB
Back to Basics 2017: Mí primera aplicación MongoDB
MongoDB
 
Tech Gupshup Meetup On MongoDB - 24/06/2016
Tech Gupshup Meetup On MongoDB - 24/06/2016
Mukesh Tilokani
 
Mongo db eveningschemadesign
Mongo db eveningschemadesign
MongoDB APAC
 
Python mongo db-training-europython-2011
Python mongo db-training-europython-2011
Andreas Jung
 
Ad

More from MongoDB (20)

MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
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
 
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.2
MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
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
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
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
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB SoCal 2020: Migrate Anything* to MongoDB Atlas
MongoDB
 
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB SoCal 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB SoCal 2020: Using MongoDB Services in Kubernetes: Any Platform, Devel...
MongoDB
 
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB SoCal 2020: A Complete Methodology of Data Modeling for MongoDB
MongoDB
 
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB SoCal 2020: From Pharmacist to Analyst: Leveraging MongoDB for Real-T...
MongoDB
 
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB SoCal 2020: Best Practices for Working with IoT and Time-series Data
MongoDB
 
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB SoCal 2020: MongoDB Atlas Jump Start
MongoDB
 
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
 
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.2
MongoDB
 
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB .local San Francisco 2020: Using MongoDB Services in Kubernetes: any ...
MongoDB
 
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB .local San Francisco 2020: Go on a Data Safari with MongoDB Charts!
MongoDB
 
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB .local San Francisco 2020: From SQL to NoSQL -- Changing Your Mindset
MongoDB
 
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB .local San Francisco 2020: MongoDB Atlas Jumpstart
MongoDB
 
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
 
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB .local San Francisco 2020: Aggregation Pipeline Power++
MongoDB
 
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
 
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB .local San Francisco 2020: MongoDB Atlas Data Lake Technical Deep Dive
MongoDB
 
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB .local San Francisco 2020: Developing Alexa Skills with MongoDB & Golang
MongoDB
 
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB .local Paris 2020: Realm : l'ingrédient secret pour de meilleures app...
MongoDB
 
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB .local Paris 2020: Upply @MongoDB : Upply : Quand le Machine Learning...
MongoDB
 
Ad

Recently uploaded (20)

Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
Introduction to Typescript - GDG On Campus EUE
Introduction to Typescript - GDG On Campus EUE
Google Developer Group On Campus European Universities in Egypt
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 
Supporting the NextGen 911 Digital Transformation with FME
Supporting the NextGen 911 Digital Transformation with FME
Safe Software
 
MuleSoft for AgentForce : Topic Center and API Catalog
MuleSoft for AgentForce : Topic Center and API Catalog
shyamraj55
 
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
“From Enterprise to Makers: Driving Vision AI Innovation at the Extreme Edge,...
Edge AI and Vision Alliance
 
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
FME for Distribution & Transmission Integrity Management Program (DIMP & TIMP)
Safe Software
 
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
“Why It’s Critical to Have an Integrated Development Methodology for Edge AI,...
Edge AI and Vision Alliance
 
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
No-Code Workflows for CAD & 3D Data: Scaling AI-Driven Infrastructure
Safe Software
 
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance Seminar State of Passkeys.pptx
FIDO Alliance
 
PyData - Graph Theory for Multi-Agent Integration
PyData - Graph Theory for Multi-Agent Integration
barqawicloud
 
The State of Web3 Industry- Industry Report
The State of Web3 Industry- Industry Report
Liveplex
 
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
ENERGY CONSUMPTION CALCULATION IN ENERGY-EFFICIENT AIR CONDITIONER.pdf
Muhammad Rizwan Akram
 
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
cnc-drilling-dowel-inserting-machine-drillteq-d-510-english.pdf
AmirStern2
 
Artificial Intelligence in the Nonprofit Boardroom.pdf
Artificial Intelligence in the Nonprofit Boardroom.pdf
OnBoard
 
Oracle Cloud and AI Specialization Program
Oracle Cloud and AI Specialization Program
VICTOR MAESTRE RAMIREZ
 
Analysis of the changes in the attitude of the news comments caused by knowin...
Analysis of the changes in the attitude of the news comments caused by knowin...
Matsushita Laboratory
 
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Scaling GenAI Inference From Prototype to Production: Real-World Lessons in S...
Anish Kumar
 
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
National Fuels Treatments Initiative: Building a Seamless Map of Hazardous Fu...
Safe Software
 
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Reducing Conflicts and Increasing Safety Along the Cycling Networks of East-F...
Safe Software
 
Providing an OGC API Processes REST Interface for FME Flow
Providing an OGC API Processes REST Interface for FME Flow
Safe Software
 
Edge-banding-machines-edgeteq-s-200-en-.pdf
Edge-banding-machines-edgeteq-s-200-en-.pdf
AmirStern2
 

Dev Jumpstart: Build Your First App with MongoDB

  • 2. Building Your First App With MongoDB Andrew Erlichson, Vice President of Engineering Developer Experience
  • 4. 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
  • 5. Terminology RDBMS MongoDB Table, View ➜ Collection Row ➜ Document Index ➜ Index Join ➜ Embedded Document Foreign Key ➜ Reference Partition ➜ Shard
  • 6. Open Source • MongoDB is an open source project • On GitHub • Licensed under the AGPL • Started & sponsored by MongoDB, Inc. • Commercial licenses available • Contributions welcome
  • 9. Full Featured • Ad Hoc queries • Real time aggregation • Rich query capabilities • Strongly consistent • Geospatial features • Support for most programming languages • Flexible schema
  • 11. Running MongoDB $ tar xvf mongodb-osx-x86_64-2.6.5.tgz $ cd mongodb-osx-x86_64-2.6.5/bin $ mkdir –p /data/db $ ./mongod
  • 12. Andrews-Air:MongoDB-SF2014 aje$ mongo MongoDB shell version: 2.6.5 connecting to: test Server has startup warnings: 2014-12-01T23:29:15.317-0500 [initandlisten] 2014-12-01T23:29:15.317-0500 [initandlisten] ** WARNING: soft rlimits too low. Number of files is 256, should be at least 1000 aje_air:PRIMARY> db.names.insert({'fullname':'Andrew Erlichson'}); WriteResult({ "nInserted" : 1 }) aje_air:PRIMARY> db.names.findOne(); { "_id" : ObjectId("547dd9a0f907ebca54d1d994"), "fullname" : "Andrew Erlichson" } aje_air:PRIMARY> Mongo Shell
  • 13. Web Demo • MongoDB • Python • Bottle web framework • Pymongo
  • 14. hello.py from pymongo import MongoClient from bottle import route, run, template @route('/') def index(): collection = db.names doc = collection.find_one() return "Hello " + doc['fullname'] client = MongoClient('localhost', 27017) db = client.test run(host='localhost', port=8080)
  • 15. @route('/') def index(): hello.py collection = db.names doc = collection.find_one() return "Hello " + doc['fullname'] client = MongoClient('localhost', 27017) db = client.test run(host='localhost', port=8080) Import the modules needed for Pymongo and the bottle web framework
  • 16. hello.py from pymongo import MongoClient from bottle import route, run, template @route('/') def index(): collection = db.names doc = collection.find_one() return "Hello " + doc['fullname'] run(host='localhost', port=8080) Connect to the MongoDB Database on Localhost and use the “test” database
  • 17. hello.py from pymongo import MongoClient from bottle import route, run, template client = MongoClient('localhost', 27017) db = client.test run(host='localhost', port=8080) Define a handler that runs when user hits the root of our web servers. That handler does a single query to the database and prints back to the web browser
  • 18. hello.py from pymongo import MongoClient from bottle import route, run, template @route('/') def index(): collection = db.names doc = collection.find_one() return "Hello " + doc['fullname'] client = MongoClient('localhost', 27017) db = client.test Start the webserver on locahost, listening on port 8080
  • 20. Determine Your Entities First Step In Your App
  • 21. Entities in our Blogging System • Users (post authors) • Posts • Comments • Tags
  • 22. We Would Start By Doing Schema Design In a relational based app
  • 23. Typical (relational) ERD tags tag_id tag post_id post_title body post_date post_author_uid post_id comment_id comment author_name comment_date author_email users uid username password Email post_id tag_id posts comments post_tags
  • 24. We Start By Building Our App And Let The Schema Evolve
  • 25. MongoDB ERD Posts title body date username [ ] comments [ ] tags Users Username password email
  • 26. Working in The Shell
  • 27. user = { _id: ’erlichson', "password" : "a7cf1c46861b140894e1371a0eb6cd6791ca2e339f1a 8d83a1846f6c81141dec,zYJue", , email: ’[email protected]', } Start with an object (or array, hash, dict, etc)
  • 28. Insert the record > db.users.insert(user) No collection creation needed
  • 29. > db.users.findOne() { "_id" : "erlichson", "password" : "a7cf1c46861b140894e1371a0eb6cd6791ca2e339f1a8d83a184 6f6c81141dec,zYJue", "email" : “[email protected]” } Querying for the user
  • 30. > db.posts.insert({ title: ‘Hello World’, body: ‘This is my first blog post’, date: new Date(‘2013-06-20’), username: ‘erlichson’, tags: [‘adventure’, ‘mongodb’], comments: [] }) Creating a blog post
  • 31.  db.posts.find().pretty() "_id" : ObjectId("51c3bafafbd5d7261b4cdb5a"), "title" : "Hello World", "body" : "This is my first blog post", "date" : ISODate("2013-06-20T00:00:00Z"), "username" : "erlichson", "tags" : [ "adventure", "mongodb" ], "comments" : [ ] } Finding the Post
  • 32. > db.posts.find({tags:'adventure'}).pretty() { "_id" : ObjectId("51c3bcddfbd5d7261b4cdb5b"), "title" : "Hello World", "body" : "This is my first blog post", "date" : ISODate("2013-06-20T00:00:00Z"), "username" : "erlichson", "tags" : [ "adventure", "mongodb" ], "comments" : [ ] } Querying an Array
  • 33. > db.posts.update({_id: new ObjectId("51c3bcddfbd5d7261b4cdb5b")}, {$push:{comments: {name: 'Steve Blank', comment: 'Awesome Post'}}}) > Using Update to Add a Comment
  • 34. > {_id: new ObjectId("51c3bcddfbd5d7261b4cdb5b")}, > Using Update to Add a Comment Predicate of the query. Specifies which document to update
  • 35. > db.posts.update({_id: new ObjectId("51c3bcddfbd5d7261b4cdb5b")}, {$push:{comments: {name: 'Steve Blank', comment: 'Awesome Post'}}}) > Using Update to Add a Comment “push” a new document under the “comments” array
  • 36. > db.posts.findOne({_id: new ObjectId("51c3bcddfbd5d7261b4cdb5b")}) { "_id" : ObjectId("51c3bcddfbd5d7261b4cdb5b"), "body" : "This is my first blog post", "comments" : [ { "name" : "Steve Blank", "comment" : "Awesome Post" } ], "date" : ISODate("2013-06-20T00:00:00Z"), "tags" : [ "adventure", "mongodb" ], "title" : "Hello World", "username" : "erlichson" } Post with Comment Attached
  • 37. Completed Blog Demo • Python • Bottle.py • Pymongo • Features Supported – Creating users – Logging in – Logging out – Displaying Content – Adding a new Blog Post
  • 45. Data Modeling Deep Dive 2pm in Robertson Auditorium 1
  • 46. Replication Internals 2pm in Fischer Banquet Room West
  • 47. MongoDB Performance Debugging 11:40am in Robertson Auditorium 3
  • 48. How to Achieve Scale 11:40am in Robertson Auditorium 2

Editor's Notes

  • #5: First what is MongoDB? What are its salient properties?
  • #6: MongoDB is document database. It’s an open source project, it strives to achieve high performance. It’s horitizontally scalabe and full featured. We will go through each of these it turn.
  • #7: By documents we don’t mean microsoft word documents or pdf files. You can think of a document as an associative array. If you use javascript, a JSON object can be stored directly into MongoDB. If you are familiat with PHP, it’s stores stuff that looks like a php array. In python, the dict is the closest analogy. And in ruby, there is a ruby hash. As you know if you use thee things, they are not flat data structures. They are hierarchical data structures. For for example, in python you can store an array within a dict, and each array element could be another array or a dict. This is really the fundamental departure from relational where you store rows, and the rows are flat.
  • #8: If you come from the world of relational, it’s useful to go through the different concept in a relational database and think about how they map to mongodb. In relational, you have a table, or perhaps a view on a table. In mongodb, we have collections. In relational, a table holds rows. In mongodb, a collection holds documents. Indexes are very similar in both technologies. In relational you can create compound indexes that include multiple columns. In mongodb, you can create indexes that include multiple keys. Relational offers the concept of a join. In mongodb, we don’t support joins, but you can “pre-join” your data by embedding documents as values. In relational, you have foreign keys, mongodb has references between collections. In relational, you might talk about partitioning the database to scale. We refer to this as sharding.
  • #9: AGPL – GNU Affero General Public License. MongoDB is open source. You can download the source right now on github. We license it under the Affero variant of the GPL. The project was initiated and is sponsored by MongoDB. You can get a commercial license by buying a subscription from MongoDB. Subscribers also receive commercial support and depending on the subscription level, access to some proprietary extensions, mostly interesting to enterprises. Contributions to the source are welcome.
  • #10: MongoDB was designed to be high performance and inexpensive to scale out. It is written in c++ and runs commodity hardware. MongoDB doesn’t use any exotic operating system extensions. The databases files themselves are memory mapped into the address space of the cpu. You can get a build for MongoDB on most platforms including windows, mac os and the major variants of linux. Big endian architectures are not supported today, which rules out ARM. MongoDB stores its data on disk using the BSON format, which can be viewed as binary JSON. BSON is also used for the wire protocol between applications and the database server. MongoDB is designed with the developer in mind. We have full support for primary and secondary indexes and as I hope to demonstrate, the document model is a lot less work as a developer.
  • #11: One of the primary design goals of MongoDB is that it be horizontally scalable. With a traditional RDBMS, when you need to handler a larger workload, you buy a bigger machine. The problem with that approach is that machines are not priced linearly. The largest computers cost exponentially more money than commodity hardware. And what’s more, if you have reasonable success in your business, you can quickly get to a point where you simply can’t buy a large enough a machine for the workload. MongoDB was designed be horizontally scalable through sharding by adding boxes.
  • #12: Well how did we achieve this horizontal scalability. If you think about the database landscape, you can plot each technology in terms of its scalability and its depth of functionality. At the top left we have the key value stores like memcached. These are typically very fast, but they lack key features to make a developer productive. On the far right, are the traditional RDBMS technologies like Oracle and Mysql. These are very full featured, but will not scale easily. And the reason that they won’t scale is that certain features they support, such as joins between tables and transactions, are not easy to run in parallel across multiple computers. MongoDB strives to sit at the knee of the curve, achieving nearly the as much scalability as key value stores, while only giving up the features that prevent scaling. So, as I said, mongoDB does not support joins or transactions. But we have certain compensating features, mostly beyond the scope of this talk, that mitigate the impact of that design decision.
  • #13: But we left a lot of good stuff in, including everything you see here. Ad hoc queries means that you can explore data from the shell using a query language (not sql though). Real time aggregation gives you much of the functionality offered by group by in sql. We have a strong consistency model by default. What that means is that you when you read data from the datbase, you read what you wrote. Sounds fairly obvious, but some systems don’t offer that feature to gain greater availability of writes. We have geospatial queries, the ability to find things based on location. And as you will see we support all popular programming languages and offer flexible, dynamic schema.
  • #14: In today’s talk, we are going to talk about building an app versus build one in real time through a demo. This session is just not long enough to actually build an app, so the entire talk is a bit meta. Sorry about that! On the plus side, I can tell you that building an app in realtime in front of an audience is something that nearly never goes well, so I am sparing you that. Step one as an app developer is to download mongodb. You can goto mongodb.org or do what most people do and google for “download mongodb” that’s going to take you to this page where you can choose an appropriate build. Even number major releases like 2.2, 2.4 are the stable releases. 64 bit is better than 32 bit. Don’t go into production with our 32 bit build. If you recall, we memory map the data files and so a 32 bit architecture limits you to 2GB of data.
  • #15: To get mongodb started, you download the tarball, expand it, cd to the directory. Create a data directory in the standard place. Now start mongodb running. That’s it.
  • #16: The first thing you will want to do after that is start the mongos hell. The mongo shell is an interaactive program that connects to mongodb and lets you perform ad-hoc queries against the database. Here you can see we have started the mongodb shell. Then we insert our first document into a collection called test. That document has a single key called “text” and it’s value is “welcome to mongodb”.’ Right after inserting it, we query the test collection and print out every document in it. There is only one, just he one we created. Plus you can see there is a strange _id field that is now part of the document. We will tallk more about that later, but the short explanation is that every document must have a unique _id value and if you don’t specify one, Mongo creates one for you.
  • #23: Alright, let’s take a step back now and better understand what a document database is since that is so central to the workings of mongodb.
  • #24: Today we are going to build a blog. A now buiding a blog Is a bit cliché buts it san application that everyone understands. You create posts, and those posts have a title. People come and comment on the blog. And perhaps you categorize your blog posts using tags. This is a screen shot of the education blog, which is built on tumblr. We won’t be building anything as full features as tumblr today, but it’s the same idea.
  • #25: Ok, the first step in building an application to manage this library is to think about what entities we need to model and maintain.
  • #26: The entities for our blog will be users, and by users we mean the authors of the blog posts. We will let people comment anonymously. We also have comments and tags.
  • #27: In a relational based solution, we would probably start by doing schema design. We would build out an ERD diagram.
  • #28: Here is the entity relationship diagram for a small blogging system. Each of these boxes represents a relational table you might have a user table, and a posts table, which holds the blog posts, and tag table, and so on. In all, if you count the tables used to relate these tables, there would be 5 tables. Let’s look at the posts table. For each post you would assign a post_id. When a comment comes in, you would put it in the comments table and also store the post_id. The post_tags table relates a post and its tags. Posts and tags are a many to many relationship. To display the front page of the blog you would need to access every table.
  • #29: In mongodb this process is turned on its head. We would do some basic planning on the collections and the document structure that would be typical in each collection and then immediately get to work on the application, letting the schema evolve over time. In mongo, every document in a collection does not need to have the same schema, although usually documents in the same collection have very nearly the same schema by convention.
  • #30: In MongoDB, you might model this blogging system with only two collections. A user collection that would hold information about the users in the system and a article collection that would embed comments, tags and category information right in the article. This way of representing the data has the benefit of being a lot closer to the way you model it within most object oriented programming languages. Rather than having to select from 8 tables to reconstruct an article, you can do a single query. Let’s stop and pause and look at this closely. The idea of having an array of comments within a blog post is a fundamental departure from relational. There are some nice properties to this. First, when I fetch the post I get every piece of information I need to display it. Second, it’s fast. Disks are slow to seek but once you seek to a location, they have a lot of throughput.
  • #31: Now I would like to turn to working within data within mongodb for blog application.
  • #32: Here is a what a document looks like in javascript object notation, or JSON. Note that the document begins with a leading parentheseis, and then has a sequence of key/value pairs. They keys are not protected by quotes. They are optional within the shell. The values are protected by quotes. In this case we have specified strings. I am inserting myself into the users collection. This is the mongo shell, which is a full javascript interpreter, so I have assigned the json document to a variable.
  • #33: To insert the user into mongodb, we type db.users. Insert(user) in the shell. This will create a new document in the users collection. Note that I did not create the collection before I used it. MongoDB will automatically create the collection when I first use it.
  • #34: If we want to retrieve that document from mongodb using the shell, we would issue the findOne command. The findOne command without any parameters will find any one document within mongodb – and you can’t specify which one. but in this case, we only have one document within the collection and hence get the one we inserted. Note that the document now has an _id field field. Let’s talk more about that. Every document must have an _id key. If you don’t specify one, the database will insert one fore you. The default type is an ObjectID, which is a 12 byte field containing information about the time, a sequence number, which client machine and which process made the request. The _id inserted by the database is guaranteed to be unique. You can specify your own _id if you desire.
  • #35: Every document must have an _id within a collection. The _id is the primary key within the collection and the _id of document must be unique within the collection. In the case we showed, we did not specify an _id and hence shell created one for us and inserted it into the database. ObjectID is the type use if the driver creates the _id. You can use any immutable value as the _id. In the case of the users collection, if we were ok with a username being immutable, we could have used that.
  • #36: "50804d0bd94ccab2da652599" is a 24 byte string (12 byte ObjectId hex encoded). The actual representation on disk is 12 bytes. The first four bytes represent a timestamp. This is useful for debugging since you can tell the order in which documents were inserted. It’s only a rough approximation of true insertion order because these _id values are generated at the client versus the mongodb server. The next three bytes identify a client machine uniquely. Typically, it’s a hash of the hostname. The next two bytes represent the processid that issued the write. Finally, there is 3 bytes of data used to distinguish between inserts done by the same process on the same client machine. We are building our application in the shell, so it’s our client in this case.
  • #37: Now it’s time to put our first blog post into the blogging system.. For our first post, we are going to say “hello world.”. Note that because we are in the mongo shell, which supports javascript, I can create a new Date object to insert the current date and time. We’ve done this w/o specifying previously what the blog collection is going to look like. This is true agile development. If we decide later to start tracking the IP address where the blog post came from, we can do that for new posts without fixing up the existing data. Of course, our application needs to understand that some keys may not be in all documents.
  • #38: Once we insert a post, the first thing we want to do is find it and make sure its there. There is only one post in the collection today so finding it is easy. We use the find command and append .pretty() on the end to so that the mongo shell prints the document in a way that is easy for humans to read. Note again that there is now an _id field for the blog post, ending in DB5A. I also inserted an emtpy comments array to make it easy to add comments later. But I could have left this out.
  • #39: Now that we have a blog post inserted, let’s look at how we would query for all blog posts that have a particular tag. This query shows the syntex for querying posts that have the tag “adventure.” This illustrates two things: first, how to query by example and second, that you can reach into an array to find a match. In this case, the query is returning all documents with elements that match the string “adventure”
  • #40: Now Let’s add a comment to the blog post. This would probably happen through a web server. For example, the user might see a post and comment on it, submitting the comment. Let’s imagine that steve blank came to my blog and posted the comment “Awesome Post.” The application server would then update the particular blog post. This query shows the syntax for an update. We specify the blog post through its _id. The ObjectID that I am creating in the shell is a throw-away data structure so that I can represent this binary value from javascript. Next, I use the $push operator to append a document to the end of the comments array. There is a rich set of query operators that start with $ within mongodb. This query appends the document with the query on the of the comments array for the blog post in question.
  • #41: Now Let’s add a comment to the blog post. This would probably happen through a web server. For example, the user might see a post and comment on it, submitting the comment. Let’s imagine that steve blank came to my blog and posted the comment “Awesome Post.” The application server would then update the particular blog post. This query shows the syntax for an update. We specify the blog post through its _id. The ObjectID that I am creating in the shell is a throw-away data structure so that I can represent this binary value from javascript. Next, I use the $push operator to append a document to the end of the comments array. There is a rich set of query operators that start with $ within mongodb. This query appends the document with the query on the of the comments array for the blog post in question.
  • #42: Now Let’s add a comment to the blog post. This would probably happen through a web server. For example, the user might see a post and comment on it, submitting the comment. Let’s imagine that steve blank came to my blog and posted the comment “Awesome Post.” The application server would then update the particular blog post. This query shows the syntax for an update. We specify the blog post through its _id. The ObjectID that I am creating in the shell is a throw-away data structure so that I can represent this binary value from javascript. Next, I use the $push operator to append a document to the end of the comments array. There is a rich set of query operators that start with $ within mongodb. This query appends the document with the query on the of the comments array for the blog post in question.
  • #43: Of course, the first thing we want to do is query to make sure our comment is in the post. We do this by using findOne, which returns one documents, and specifying the document with the same _id. The comment is within the document in yellow. Note that mongodb has decided to move the comment key within the document. This makes the point that the exact order of keys within a document is not guaranteed.
  • #45: If this was a real application it would have a front end UI and that UI would not be having the user login to the mongo shell.
  • #46: There are drivers that are created and maintained by 10gen for most popular languages. You can find them at api.mongodb.org.
  • #47: There are also drivers maintained by the community. Drivers connect to the mongodb servers. They translate BSON into native types within the language. Also take care of maintaining connections to replica set. The mongo shell that I showed you today is not a driver, but works like one in some ways. You install a driver by going to api.mongodb.org, clicking through the documentation for a driver and finding the recommended way to install it on your computer. For example, for the python driver, you use pip to install it, typically.
  • #50: We’ve covered a lot of ground in a pretty short time but still have barely scratched the surface of how to build an application within mongodb. To learn more about mongodb, you can use the online documentation, which is a great resource.
  • #54: There are also introductory talks that delve deeper into many of the topics we covered here today. At 11:05, Gary Murakamiis discussing schema design within MongoDB.
  • #55: Randall Hunt is discussing replication. Replication is the way we achieve high availability and fault tolerance within mongodb.
  • #56: 10gen CEO Max Schireson is talking about indexing at 12:40pm