document-oriented database
Antoine Girbal
antoine@10gen.com
Data Store Analytics
RDBMS
Helper
RDBMS
(MemCache, New Gen.
Application layer)
(Oracle, MySQL) OLAP
(vertica, aster,
greenplum)
Non-relational
Operational Stores
(“NoSQL”)
NoSQL Really Means:
non-relational, next-generation
operational datastores and databases
focus on scalability
ease of modeling and changing data
(also no sql syntax, thanks!)
no joins
+ no complex transactions
Horizontally Scalable
Architectures
JSON-style Documents
Just like a light and friendly XML
{ hello: “world” }
represented as BSON
\x16\x00\x00\x00\x02hello\x00
\x06\x00\x00\x00world\x00\x00
http://bsonspec.org
Flexible “Schemas”
In collection db.posts:
{author: “mike”,
links: 3,
date: "Sun Jul 18 2010 14:40:20 GMT-0700 (PDT)"
text: “blah blah”}
{author: “eliot”,
date: "Sun Jul 18 2010 14:40:22 GMT-0700 (PDT)"
text: “Here is MongoDB ...”,
views: 10}
PERFORMANCE
As fast as BLOBs if well
Easy to scale (Dynamo)
Can't scale modeled, horizontal
can easily use caching
scalability
FEATURES
Most regular SQL
(too) many No feature
features (satisfies 90% of
users)
Features
• Complex querying
• Atomic updates with modifiers
• Indexing (unique, compound, Geo)
• Aggregation and Map / Reduce
• Capped Collections
• Powerful Shell (Javascript)
• GridFS: file storage
Replication
Using Replica Set:
- pool of servers with 1 master
- automatic master election and failover
- distributed reads (slaveOk)
Client Client
master
mongod
mongod
mongod
mongod
mongod
mongod
mongod
mongod
mongod
...
Config ...
Servers
mongod
mongod
client
Support
• OS: Mac OS X, Windows, Linux, Solaris,
32/64 bits
• Drivers: C, C#, C++, Haskell, Java,
Javascript, Perl, PHP, Python, Ruby, Scala...
+ community drivers
• Open-source project with active
community, Wiki, Google Group, 10gen
consulting / support
Production Examples
Shutterfly
Intuit
Fourquare
College humor
Craigslist
Evite
bit.ly
Disqus
IGN
Justin.tv
Sourceforge
Heartbeat
Etsy
Hot Potato
the New York Times
Eventbrite
Business Insider
Sugar crm
Gilt Groupe
Electronic Arts
...
New Post
> post = {author: "mike",
... date: new Date(),
... text: "my blog post",
... tags: ["mongodb", "intro"]}
> db.posts.save(post)
> db.posts.findOne()
{ "_id" : ObjectId("4d2f944103e8fdbb36f6d205"),
"author" : "mike",
"date" : ISODate("2011-01-14T00:08:49.933Z"),
"text" : "my blog post",
"tags" : ["mongodb","intro"]}
A Quick Aside
Paging:
> page = 2
> page_size = 15
> db.post.find().limit(page_size).skip(page * page_size)
Advanced operators:
$gt, $lt, $gte, $lte, $ne, $all, $in, $nin, $where
> db.posts.find({$where: "this.author == 'tony' || this.title == 'foo'"})
Download MongoDB
Current 1.6, soon 1.8
http://www.mongodb.org