3. Agenda
What is MongoDB ?
Try MongoDB using Vagrant
About Vagrant and Why is it is useful for hands-on
4. What is MongoDB ?
Hybrid of NoSQL and RDB
Stores JSON document as ‘BSON’
Capped collection : Log storage made easy
Has Seconday Index ( on any part of JSON Doc), Query Optimizer,
GeoLocation index
Replication, Sharding ready
Drivers in lots of languages … and many more. Rich.
5. JavaScript based queries
Queries written in JavaScript. ex)
db.reviews.find({'_id':
product['id']}).sort( {details.m
odel_num: -1}).limit(12)
If possible, the optimizer
automatically uses an index to
accelerate
Secondary index can be made on
deep elements of the documents
{ _id: ObjectId(“…”), !
sku: "9092",!
details: {
model_num: 4039283402, !
manufacturer: "Acme", !
manufacturer_id: 432, !
color: "Green"!
} !
}!
details.color can be indexed
6. !
Schemalessness : pros and cons
MongoDB stores JSON : You don’t have to define
schemas beforehand
Good for prototyping, document-like data
Could be dangerous : may lead to degrade, tests & CI are
answers ( to some extent ) ?
7. Browser(AngularJS)
The Trend for Web App :
MEAN Stack
MongoDB (JSON Storage)
Express
(Web Application Framework for Node.js)
AngularJS
(JavaScript framework for Web Client)
Node.js
(JavaScript powered Web Server)
And more…
Twitter Bootstrap (CSS Framework)
DOM
Model(JSON)
Express & Node.js
2way data bind
8. ReplicaSet :
Availability & Scalability for reads
Automatic Failover
Setup is very easy
Can write to Primary only
Can read from any nodes
Primary
Node
Secondary
Node
Secondary
Node
heartbeats
replication
9. ReplicaSet :
When primary failed
One of the Secondaries will
take over the Primary role
Writing to the ReplicaSet
once returns error, then
next write will be succeed.
The driver take care of
dirty-hand jobs of
reconnection
Primary
Node
Primary
Node
Secondary
Node
heartbeats
replication
10. ReplicaSet :
When the node returned
Rejoin to the ReplicaSet as
a Secondary node
Data recovery will be
handled transparently to
the user (hopefully)
Secondary
Node
Primary
Node
Secondary
Node
heartbeats
replication
11. Primary
Node
Sharding :
Scalability for writes
Scales write performance
Mongos routes requests
according to the value of shard
key
Availability gets lower : Normaly
used with ReplicaSet
Choose shard key so that the
write requests are distributed
among the shards
Primary
Node
replication
Shard 1
Primary
Node
Primary
Node
Shard 2
Primary
Node
Primary
Node
Shard N
mongos
(router)
13. About Vagrant
and Why is it is useful for hands-on
It often happens …
You wrote a perfect scenario for the meetup
You confirmed that the scenario ‘works perfect on
your machine’ :)
At the meetup, you found that many attendee says ‘It
doesn’t work on my machine’ :(
14. Here comes Vagrant
to the RESQUE !
Hands-on goes inside ‘clean’ virtual machines
- no more ‘it worked on my machine’ problem
Only Vagrant and VirtualBox are needed before hands-on
(they’re extremely easy to setup!)
Configurations and provisioning scripts can be managed
with SCMs like Git
15. Thanks for listening !
Upcoming Titles ( and talk ? ) :
September : Test driven Infrastructure with Chef
December : Selenium Web Driver practical guide