4. What?
• A collection of very different products
• Not relational
• No joins
• Currently not using SQL
• Allows much more flexible data structures than RDBMS
Wednesday 31 October 12
6. Who? What?
• 10gen created MongoDB in 2007
• Founded by Eliot Horowitz and Dwight Merriman
• Inspired by work on DoubleClick, ShopWiki and Panther
Express
• Over 170 people
• Funded by: Sequoia, Flybridge Capital, Union Square
Ventures & New Enterprise Associates
• Offices in New York (HQ), Palo Alto, London, Dublin and
Sydney
Wednesday 31 October 12
7. When?
• Coding started fall 2007
• First production site March 2008 - businessinsider.com
• Open Source - AGPL
• Version 0.8 – first official release February 2009
• Version 1.0 – August 2009
• Version 2.0 – September 2011
• Version 2.2 - September 2012
Wednesday 31 October 12
13. Insert
• You should see something like:
“Inserted 1 record(s) in 2ms”
• db.test.insert({name: “mark”, surname:
“hillick”, weight: 170})
Wednesday 31 October 12
14. Find
• db.test.find({name: “mark”})
• You should see something like:
“{ "_id":
ObjectId("509108ff707a9dd29312054e"),
"name": "mark", "surname": "mark", "weight":
170 }”
Wednesday 31 October 12
15. Update
• db.name.update({name: 'mark'}, {$set:
{weight: 169}})
• You should see something like:
“Updated 1 existing record(s) in 0ms”
Wednesday 31 October 12
16. Delete
• You should see something like:
“Removed 1 record(s) in 0ms”
• db.name.remove({name: “mark”})
Wednesday 31 October 12
18. Where to Download
• Binaries: http://www.mongodb.org/downloads
• Subscription: http://ww.mongodb.org/mongodb-
subscriber-edition-download
• SSL & SNMP
• Source: https://github.com/mongodb/mongo
• Packages: RH-type & Ubuntu/Debian
Wednesday 31 October 12
19. What now?
• How To Install: http://docs.mongodb.org/manual/
installation/
• Release Notes: http://docs.mongodb.org/manual/
release-notes/
Wednesday 31 October 12
22. Types of outage
• Resilience
• Reliability
• Protect against planned & unplanned outages
Wednesday 31 October 12
23. How MongoDB Replication works
Member
1
Member
2
Member
3
•Set is made up of 2 or more nodes
Wednesday 31 October 12
24. How MongoDB Replication works
Member
1
Member
2
PRIMARY
Member
3
•Election establishes the PRIMARY
•Data replication from PRIMARY to SECONDARY
Wednesday 31 October 12
25. How MongoDB Replication works
Member
1
Member
2
DOWN
Member
3
negotiate
new
master
•PRIMARY may fail
•Automatic election of new PRIMARY if majority
exists
Wednesday 31 October 12
26. How MongoDB Replication works
Member
1
Member
2
DOWN
Member
3
PRIMARY
•New PRIMARY elected
•Replication Set re-established
Wednesday 31 October 12
27. How MongoDB Replication works
Member
1
Member
2
RECOVERING
Member
3
PRIMARY
•Automatic recovery
Wednesday 31 October 12
28. How MongoDB Replication works
Member
1
Member
2
Member
3
PRIMARY
•Replication Set re-established
Wednesday 31 October 12
35. MongoDB Sharding
• Automatic partitioning and management
• Range based
• Convert to sharded system with no downtime
• Fully consistent
Wednesday 31 October 12
36. How MongoDB Sharding works
>
db.posts.save(
{age:40}
)
-∞ +∞
-∞ 40 41 +∞
•Data in inserted
•Ranges are split into more “chunks”
Wednesday 31 October 12
54. Documentation & Features
• Doc: http://www.mongodb.org/display/DOCS/Drivers
• Official
• C, C++, Java, PHP, Python, Ruby, Scala & more
• Community
Wednesday 31 October 12
57. db.blogs.ensureIndex({author:
1})
1
=
ascending
-‐1
=
descending
An
index
on
_id
is
automatic.
For
more
use
ensureIndex:
Creating Indexes
Wednesday 31 October 12
58. Compound Indexes
db.blogs.save({
author:
"James",
ts:
new
Date()
...
});
db.blogs.ensureIndex({author:
1,
ts:
-‐1})
Wednesday 31 October 12
59. db.blogs.save({
title:
"My
First
blog",
comments:
[
{author:
"James",
ts
:
new
Date()}
]
});
db.blogs.ensureIndex({"comments.author":
1})
db.blogs.find({"comments.author":
"James"})
Indexing Embedded Arrays
Wednesday 31 October 12
60. db.blogs.save({
loc:
{
long:
40.739037,
lat:
40.739037
}
});
db.blogs.save({
loc:
[40.739037,
40.739037]
});
db.blogs.ensureIndex({"loc":
"2d"})
Geospatial
• Geo hash stored in B-Tree
• First two values indexed
Wednesday 31 October 12
62. Documentation & Features
• New: http://docs.mongodb.org/manual/security/
• Linux
• Windows
• AMI
• Authentication
• SSL
• NoSQL solutions behind traditional RDBMs
Wednesday 31 October 12
68. Where
• Open-Source Community
• Contribute - tell us your thoughts!!!
• Support provided By 10gen & Community on Google
Groups [ groups.google.com/group/mongodb-user]
• jira.mongodb.org: features, commercial support,
security, bugs, drivers etc
Wednesday 31 October 12
72. MUGs
• Right Here in Dublin: http://mongodb.meetup.com/
cities/ie/dublin/ :)
• Complete List: http://www.mongodb.org/display/
DOCS/MongoDB+User+Groups+(MUGs)
Wednesday 31 October 12
73. Dublin
• Next MeetUp: Thursday, December 6th @ EngineYard
• Poll: http://www.meetup.com/DublinMUG/polls/
Source: http://www.feedhenry.com Source: http://www.iamstaggered.com/wp-content/
uploads/2011/03/dublin.jpg
Wednesday 31 October 12