SlideShare a Scribd company logo
Quick & Dirty & MEAN
21 May 2016, Cowork South Bay
Troy Miles
Quick & Dirty & MEAN
Text
Want more? Follow me, new tutorials are announced on Twitter first:
@therockncoder
Resources
http://www.slideshare.net/rockncoder/mean-stack-
weekend
https://github.com/Rockncoder/quizzer-start
https://github.com/Rockncoder/quizzer-ng2
Troy Miles
Troy Miles aka the RocknCoder
Over 36 years of programming experience
Author of jQuery Essentials
Speaker and writer on all things web & mobile
rockncoder@gmail.com
@therockncoder
Agenda
Introduction to MongoDB
Installing MongoDB
Riding the BSON
Enter the Mongo (part 1)
BREAK
The Other Mongo Apps
Importing Data
LUNCH
Enter the Mongo (part 2)
Indexing
BREAK
Agenda (continue)
Going Global
MongoDB in Programs
Advanced MongoDB
MongoDB Tools
MongoDB as a Service
Exploring the MongoDB
Website
Summary
How to get the most out of
this class
Follow along
Complete each exercise
Ask questions and for clarification
Don’t worry about asking questions, I like them
Use what you’ve learned after the class is over
Introduction to MongoDB
What is MongoDB?
Cross-platform document database
Developed by MongoDB Inc in 2007
Production ready since March 2010
Free and open-source
The current version is 2.6.4
Top DB-Engines
1. Oracle
2. MySQL
3. MS SQL Server
4. PostgreSQL
5. MongoDB
6. DB2
7. MS Access
8. SQLite
9. Cassandra
10.Sybase ASE
Who Uses It?
Craigslist
eBay
Foursquare
SourceForge
Viacom
Expedia
Parse
LinkedIn
Medtronic
eHarmony
CERN
and more
Why?
Document Database
High Performance
High Availability
Easy Scalability
What is a Document?
An ordered set of keys and values
like JavaScript objects
no duplicate keys allowed
type and case sensitive
field order is not important nor guaranteed
MongoDB Myths
It is schema-less
You don’t need to design db
You can mix types, therefore you should
What’s Wrong with SQL?
SQL was created by Edgar F. Codd in 1969
Oracle V2 introduced in 1979
MS SQL Server introduced in 1989
Most languages today are object-oriented
SQL is column and row oriented
A Contact Manager
first name
last name
home address
work address
mobile phone
home phone
In SQL
Person table
Address table
Phone number table
Joins necessary to retrieve complete record
In MongoDB
One collection holds it all
Including the arrays
No joins necessary
SQL MongoDB
row document
table collection
database database
joins none
transactions none
Installing MongoDB
Section Goals
Get MongoDB installed
on everyone’s laptop
Run mongod command
MongoDB is ready to go
to work
www.mongodb.org
This is the home of MongoDB
The best place to download executables and drivers
Installation
The current version is 3.2
Downloads available for Windows, Linux, Mac OSX,
and Solaris
64-bit for all systems, 32-bit for Windows & Linux
32-bit is not recommended
Windows
Determine your machine’s architecture (64 or 32 bit)
wmic os get osarchitecture
Download & run the MongoDB msi file
Create the data directory
md datadb
Run MongoDB from a command window
mongod
Mac OS X
Open Terminal
Extract the archive
tar -zxvf mongodb-osx-x86_64-2.6.3.tgz
Copy the files to the target directory
mkdir -p mongodb
cp -R -n mongodb-osx-x86_64-2.6.3/ mongodb
Mac OS X
Create the data directory
mkdir -p /data/db
Run MongoDB
mongod
Section Summary
Everyone should have MongoDB installed
MongoDB should be running in a terminal or command
window
Riding the BSON
Section Goals
Introduce the data types
available in MongoDB
Give a decent
explanation of why
MongoDB uses BSON
and not JSON
BSON not JSON
MongoDB uses its own variant of JSON
Called Binary JSON or BSON
Efficiency
Traversability
Performance
Data Types
Double
String
Object
Array
Binary data
Undefined
Object id
Boolean
Date
Null
Reg Ex
JavaScript
Symbol
32 bit Integer
Timestamp
64 bit Integer
Min key
Max key
Object
An unordered set of name/value pairs
The name is any valid string
The name may be unquoted if it is not a reserved
The value may be any of the other valid types including
another object or an array
Array
An ordered collection of values
Begins and ends with square brackets
The values can be any of the other types
Binary data aka BinData
Used to represent arrays of bytes
Somewhat like a ByteArray in Java or byte[] in C#
Can be used in equal comparisons
Other comparisons exist but might produce some
weird results
Object id
12-byte BSON type
4 bytes for the number of seconds since Jan 1, 1970
3 bytes for the machine id
2 bytes for the process id
3 bytes for a counter which begins with a random
Date
64 bit Integer
Not related to the Timestamp type
Represents the number of milliseconds since 1 January
1970
Date has a time range of plus or minus 290 million years
No chance of a Y2K problem anytime soon
Timestamp
64 bit Integer
Not related to the Date type
First 32 bits represents the seconds since Jan 1, 1970
Second 32 bits is an incrementing ordinal
Within a mongod instance timestamps are unique
Regular Expression (Reg Ex)
A string representing a JavaScript style regular
expression
Regular expressions give MongoDB the ability to do
something like SQL LIKE operation
JavaScript
A string representing a JavaScript program
The program can be stored with or without scope
Care should be used in executing JavaScript on the
server side since it operates in the JavaScript shell
Limits
A document has a max size of 16 MB
Documents can’t be nest any more than a 100 levels
The namespace which includes the database and
collection names must be shorter than 123
No single collection can have more than 64 indexes
Section Summary
MongoDB has all of the expected data types
And a few surprising ones
Exercise caution when JavaScript type
Enter the Mongo (part 1)
Section Goals
Introduce the MongoDB
Interactive Shell
Work through some of
the shells commands
The MongoDB Shell
Allows interactions with a MongoDB instance
A full-featured JavaScript interpreter
Allows multiple line input
Enter the Mongo
From the command or terminal window enter mongo
and press enter
You should see a greater than sign “>”
You can exit the shell by entering exit
Commands
Mongo has a lot of commands
Some are global and operate against the environment
Others refer only to databases and are preceded by db.
There also commands which refer to a collection, they 

db.<Collection Name>.<command>
The most important command is help
Creating a database
To make sure we are all on the same page we are
going to create a database named “m95”
To create a database Enter: use m95
If you want to delete a database, you need to drop it,
Enter db.dropDatabase()
Be careful there is no confirmation
Inserting Documents
Having a database is nice, nicer still is having data in it
To insert data, db.<Collection Name>.insert(…)
Don’t worry about the collection name, if it doesn’t
exist, it will be created
Reading Documents
In order to read the documents which we have created
we need to use the find command

db.<Collection Name>.find()
In order to find just the documents we are looking for,
we need to add a selector
The simplest is the equality selector
.find({key: value})
More selectors
$ne - not equal
$gt, $gte - greater than, greater than or equal to
$lt, $lte - less than, less than or equal to
$not - logical not
Deleting Documents
remove - deletes documents
Without a selector it will delete all documents in a
collection - BE CAREFUL
Updating Documents
.update({selector}, {data to update})
The update quirk
.update({selector}, {$set, {data to update}});
Update Modifiers
.update({selector}, {$inc: {data to increment}})
.update({selector}, {push: {data to push}})
Section Summary
Everyone should know how to enter and exit the shell
How to basic operations
How to get help
The Other Mongo Apps
mongodump
It backs up the data, it doesn’t dump it
You must have the backup role
Must have read access on the database
Super simple - mongodump
Creates a directory
mongorestore
restores a backed up database
Must have admin access and restore role
mongorestore —port <port no#> <path to backup>
mongoexport
Exports data in a MongoDB instance in either CSV or
JSON format
mongoexport —db <name> —collection <c name> —
csv
mongoimport
Imports JSON, CSV, or TSV files into mongod
mongostat
A short status report of the currently running mongos
mongostat
Importing Data
Enter the Mongo (part 2)
Advanced MongoDB
Performance
Indexing
Query Optimization
Profiler
Indexing
Indexes should support queries
Use indexes to sort queries
Indexes should fit into RAM
Queries should ensure selectivity
Query Optimization
Improves read operations by reducing data that the
query needs to process
Profiler
Collects data about MongoDB database commands
Enabled per-database or per-instance basis
Profile level is configurable (0, 1, or 2)
Stats
db.stats()
Statistics that reflect the use of a single DB
Identifies:
the current database
the number of indexes
the file size
Replication
Keeps identical copies of data on multiple servers
Set up by creating a replica set
A replica set is a group of servers with one primary
If primary crash, secondaries elect a new one
Sharding
Process of splitting data up across machines
Manual sharding can be with most database
MongoDB has autosharding
Nonetheless it is difficult to configure
MongoDB Tools
Tools
MongoDB Shell (built-in)
MongoDB Web Site (built-in)
Robomongo (Mac, PC, Linux)
http://mongodb-tools.com/
MongoDB as a Service
MongoDB as a Service
Why?
Setting up a remote database
Switching between dev and production
MongoHQ
https://www.mongohq.com/
Free developer's sandbox
Includes web based data browser
MongoLab
https://mongolab.com/welcome/
Free developer's sandbox
Includes web based data browser
MongoDirector
http://www.mongodirector.com/index.html
Free 30 day trial
Both public cloud and self-hosting supported
ObjectRocket
http://www.objectrocket.com/
Plans from $19 a month / 1 GB
Auto-sharding included
Included daily backups
Summary
MongoDB is an open-source document database
It features JSON-style documents with dynamic
schemas
In order to gain performance, it sacrifices reliability
https://bitly.com/bundles/rockncoder/2

More Related Content

PDF
Build a Game in 60 minutes
PDF
Game Design and Development Workshop Day 1
PDF
Kernel linux lab manual feb (1)
PDF
Linux Containers (LXC)
PDF
Programming IoT Gateways in JavaScript with macchina.io
PDF
Faster and Easier Software Development using Docker Platform
PDF
Docker for the Internet of Things (IoT): An Introduction
PDF
Programming IoT with Docker: How to Start?
Build a Game in 60 minutes
Game Design and Development Workshop Day 1
Kernel linux lab manual feb (1)
Linux Containers (LXC)
Programming IoT Gateways in JavaScript with macchina.io
Faster and Easier Software Development using Docker Platform
Docker for the Internet of Things (IoT): An Introduction
Programming IoT with Docker: How to Start?

What's hot (19)

PPTX
Tech talk on docker with demo
PDF
Introduction to Docker (and a bit more) at LSPE meetup Sunnyvale
PPTX
Once Upon a Process
PPTX
Docker for Web Developers: A Sneak Peek
PDF
Containerizing Web Application with Docker
PPTX
Docker Warsaw Meetup 12/2017 - DockerCon 2017 Recap
PDF
Docker and Your Path to a Better Staging Environment - webinar by Gil Tayar
PDF
Docker: A New Way to Turbocharging Your Apps Development
PDF
Redis — The AK-47 of Post-relational Databases
PDF
Eric Lafortune - Fighting application size with ProGuard and beyond
PDF
Docker as an every day work tool
PDF
From zero to Docker
PDF
App container rkt
PDF
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
PDF
Bh Usa 07 Butler And Kendall
PDF
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
PDF
Data Science Workflows using Docker Containers
PDF
Introduction to Docker (as presented at December 2013 Global Hackathon)
PPTX
Docker Internals - Twilio talk November 14th, 2013
Tech talk on docker with demo
Introduction to Docker (and a bit more) at LSPE meetup Sunnyvale
Once Upon a Process
Docker for Web Developers: A Sneak Peek
Containerizing Web Application with Docker
Docker Warsaw Meetup 12/2017 - DockerCon 2017 Recap
Docker and Your Path to a Better Staging Environment - webinar by Gil Tayar
Docker: A New Way to Turbocharging Your Apps Development
Redis — The AK-47 of Post-relational Databases
Eric Lafortune - Fighting application size with ProGuard and beyond
Docker as an every day work tool
From zero to Docker
App container rkt
Cgroups, namespaces, and beyond: what are containers made from? (DockerCon Eu...
Bh Usa 07 Butler And Kendall
Build and Run Containers With Lazy Pulling - Adoption status of containerd St...
Data Science Workflows using Docker Containers
Introduction to Docker (as presented at December 2013 Global Hackathon)
Docker Internals - Twilio talk November 14th, 2013
Ad

Viewers also liked (18)

PPTX
Scaling Systems: Architectures that Grow
PPTX
Scaling Systems: Architectures that grow
PPTX
Token Based Authentication Systems with AngularJS & NodeJS
ODP
PPTX
Presentation1
PPT
2 do 1 more work
PPT
Organizacion
PDF
The 7 deadly sins of financial modelling / ModelOff Seminar
PPTX
Presentación avances de investigación del doctorado (oct 16)
PPTX
Sineace Coneau Peru
PDF
Collaborative Line of Business Applications on IBM Bluemix
PPTX
Modelo de acreditación para programas de educación superior
PPTX
3.2 pedagogía cognitivista
DOCX
Liderazgo y manejo de grupos
PDF
ORGANIC CHEMISTRY INTRODUCTION
PPTX
Rcm business plan book
PPTX
Oral Medicine :Burning mouth syndrome
Scaling Systems: Architectures that Grow
Scaling Systems: Architectures that grow
Token Based Authentication Systems with AngularJS & NodeJS
Presentation1
2 do 1 more work
Organizacion
The 7 deadly sins of financial modelling / ModelOff Seminar
Presentación avances de investigación del doctorado (oct 16)
Sineace Coneau Peru
Collaborative Line of Business Applications on IBM Bluemix
Modelo de acreditación para programas de educación superior
3.2 pedagogía cognitivista
Liderazgo y manejo de grupos
ORGANIC CHEMISTRY INTRODUCTION
Rcm business plan book
Oral Medicine :Burning mouth syndrome
Ad

Similar to Quick & Dirty & MEAN (20)

PPT
MongoDB Pros and Cons
DOCX
Mongo db report
PDF
Mongodb By Vipin
PDF
MongoDB
PPTX
MongoDB for Beginners
PPTX
MongoDB installation,CRUD operation & JavaScript shell
PPT
A Brief MongoDB Intro
PDF
Experiment no 1
PDF
Mongodb Introduction
PDF
Mdb dn 2016_06_query_primer
PPT
Introduction to mongodb
PDF
How to use MongoDB with CakePHP
PPTX
Mongo db
PPTX
Sekilas PHP + mongoDB
PDF
Mdb dn 2016_07_elastic_search
PDF
Introduction to MongoDB and its best practices
PDF
Open source Technology
PPTX
How Thermo Fisher is Reducing Data Analysis Times from Days to Minutes with M...
PPTX
Mongodb Introduction
PPTX
Introduction to MongoDB
MongoDB Pros and Cons
Mongo db report
Mongodb By Vipin
MongoDB
MongoDB for Beginners
MongoDB installation,CRUD operation & JavaScript shell
A Brief MongoDB Intro
Experiment no 1
Mongodb Introduction
Mdb dn 2016_06_query_primer
Introduction to mongodb
How to use MongoDB with CakePHP
Mongo db
Sekilas PHP + mongoDB
Mdb dn 2016_07_elastic_search
Introduction to MongoDB and its best practices
Open source Technology
How Thermo Fisher is Reducing Data Analysis Times from Days to Minutes with M...
Mongodb Introduction
Introduction to MongoDB

More from Troy Miles (20)

PDF
Fast C++ Web Servers
PDF
Node Boot Camp
PDF
AWS Lambda Function with Kotlin
PDF
React Native One Day
PDF
React Native Evening
PDF
Intro to React
PDF
React Development with the MERN Stack
PDF
Angular Application Testing
PDF
ReactJS.NET
PDF
What is Angular version 4?
PDF
Angular Weekend
PDF
From MEAN to the MERN Stack
PDF
Functional Programming in JavaScript
PDF
Functional Programming in Clojure
PDF
MEAN Stack Warm-up
PDF
The JavaScript You Wished You Knew
PDF
A Quick Intro to ReactiveX
PDF
JavaScript Foundations Day1
PDF
AngularJS Beginner Day One
PDF
AngularJS on Mobile with the Ionic Framework
Fast C++ Web Servers
Node Boot Camp
AWS Lambda Function with Kotlin
React Native One Day
React Native Evening
Intro to React
React Development with the MERN Stack
Angular Application Testing
ReactJS.NET
What is Angular version 4?
Angular Weekend
From MEAN to the MERN Stack
Functional Programming in JavaScript
Functional Programming in Clojure
MEAN Stack Warm-up
The JavaScript You Wished You Knew
A Quick Intro to ReactiveX
JavaScript Foundations Day1
AngularJS Beginner Day One
AngularJS on Mobile with the Ionic Framework

Recently uploaded (20)

PDF
Design an Analysis of Algorithms I-SECS-1021-03
PPTX
history of c programming in notes for students .pptx
PDF
Complete Guide to Website Development in Malaysia for SMEs
PDF
Wondershare Filmora 15 Crack With Activation Key [2025
DOCX
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
PDF
Autodesk AutoCAD Crack Free Download 2025
PDF
Navsoft: AI-Powered Business Solutions & Custom Software Development
PDF
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
PDF
Cost to Outsource Software Development in 2025
PDF
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
PDF
Internet Downloader Manager (IDM) Crack 6.42 Build 41
PDF
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
PPTX
assetexplorer- product-overview - presentation
PPTX
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
PPTX
Oracle Fusion HCM Cloud Demo for Beginners
PPTX
Operating system designcfffgfgggggggvggggggggg
PDF
Adobe Illustrator 28.6 Crack My Vision of Vector Design
PDF
AutoCAD Professional Crack 2025 With License Key
PDF
wealthsignaloriginal-com-DS-text-... (1).pdf
PDF
How to Choose the Right IT Partner for Your Business in Malaysia
Design an Analysis of Algorithms I-SECS-1021-03
history of c programming in notes for students .pptx
Complete Guide to Website Development in Malaysia for SMEs
Wondershare Filmora 15 Crack With Activation Key [2025
Greta — No-Code AI for Building Full-Stack Web & Mobile Apps
Autodesk AutoCAD Crack Free Download 2025
Navsoft: AI-Powered Business Solutions & Custom Software Development
How to Make Money in the Metaverse_ Top Strategies for Beginners.pdf
Cost to Outsource Software Development in 2025
CCleaner Pro 6.38.11537 Crack Final Latest Version 2025
Internet Downloader Manager (IDM) Crack 6.42 Build 41
Adobe Premiere Pro 2025 (v24.5.0.057) Crack free
assetexplorer- product-overview - presentation
Log360_SIEM_Solutions Overview PPT_Feb 2020.pptx
Oracle Fusion HCM Cloud Demo for Beginners
Operating system designcfffgfgggggggvggggggggg
Adobe Illustrator 28.6 Crack My Vision of Vector Design
AutoCAD Professional Crack 2025 With License Key
wealthsignaloriginal-com-DS-text-... (1).pdf
How to Choose the Right IT Partner for Your Business in Malaysia

Quick & Dirty & MEAN