SlideShare a Scribd company logo
open-­‐source,	
  high-­‐performance,	
  
            document-­‐oriented	
  database



Mike	
  Dirolf	
  	
  	
  •	
  	
  	
  10gen,	
  Inc.	
  	
  	
  •	
  	
  	
  @mdirolf	
  	
  	
  •	
  	
  	
  http://dirolf.com
Non-relational
                         Operational Stores
                                    (“NoSQL”)




New Gen. OLAP                                     RDBMS
(vertica,	
  aster,	
  greenplum)               (Oracle,	
  MySQL)
NoSQL Really Means:
 non-­‐relational,	
  next-­‐generation	
  
 operational	
  datastores	
  and	
  databases
no	
  joins
+   no	
  complex	
  transactions

Horizontally Scalable
        Architectures
no	
  joins
+   no	
  complex	
  transactions

    New Data Models
New Data Models
improved	
  ways	
  to	
  develop	
  applications?
Data Models
    Key	
  /	
  Value
 memcached,	
  Dynamo

      Tabular
       BigTable

Document	
  Oriented
 MongoDB,	
  CouchDB
• memcached
scalability	
  &	
  performance



                                      • key/value



                                                                            •   RDBMS




                                             depth	
  of	
  functionality
JSON-style Documents
           represented	
  as	
  BSON

      {“hello”:	
  “world”}

  x16x00x00x00x02hello
  x00x06x00x00x00world
  x00x00


                            http://bsonspec.org
Flexible “Schemas”

                        {“author”:	
  “eliot”,
{“author”:	
  “mike”,
                        	
  “text”:	
  “...”,
	
  “text”:	
  “...”}
                        	
  “tags”:	
  [“mongodb”]}
Dynamic Queries
Atomic Update
  Modifiers
Focus on Performance
Replication
                            master   slave

        master
                            master   slave


slave       slave   slave   master   master

                             slave   master
Auto-sharding
                   Shards
          mongod   mongod    mongod
                                            ...
Config     mongod   mongod    mongod
Servers

mongod

mongod

mongod
                   mongos    mongos   ...


                    client
Many Supported
Platforms / Languages
Best Use Cases
                                        T

Scaling	
  Out
                              Caching
                 The	
  Web

            High	
  Volume
Less Good At
     highly	
  transactional


ad-­‐hoc	
  business	
  intelligence


problems	
  that	
  require	
  SQL
A Quick Aside
_id                  special	
  key
  present	
  in	
  all	
  documents
 unique	
  across	
  a	
  Collection
           any	
  type	
  you	
  want
Post

{:author	
  =>	
  “mike”,
	
  :date	
  =>	
  Time.new,
	
  :text	
  =>	
  “my	
  blog	
  post...”,
	
  :tags	
  =>	
  [“mongodb”,	
  “ruby”]}
Comment

{:author	
  =>	
  “eliot”,
	
  :date	
  =>	
  Time.new,
	
  :text	
  =>	
  “great	
  post!”}
New Post
post	
  =	
  {:author	
  =>	
  “mike”,
	
  	
  :date	
  =>	
  Time.new,
	
  	
  :text	
  =>	
  “my	
  blog	
  post...”,
	
  	
  :tags	
  =>	
  [“mongodb”,	
  “ruby”]}

db[“posts”].save(post)
Embedding a Comment

c	
  =	
  {:author	
  =>	
  “eliot”,
	
  	
  :date	
  =>	
  Time.new,
	
  	
  :text	
  =>	
  “great	
  post!”}

db[“posts”].update({:_id	
  =>	
  post[:_id]},	
  
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  {:$push	
  =>	
  {:comments	
  =>	
  c}})
Posts by Author


db[“posts”].find(:author	
  =>	
  “mike”)
Last 10 Posts

db[“posts”].find
	
  	
  .sort([[:date,	
  :desc]])
	
  	
  .limit(10)
Posts Since April 1


april_1	
  =	
  Time.utc(2010,	
  4,	
  1)

db[“posts”].find(:date	
  =>	
  {:$gt	
  =>	
  april_1})
Posts Ending With ‘Ruby’


db[“posts”].find(:text	
  =>	
  /Ruby$/)
Posts With a Tag
db[“posts”].find(:tags	
  =>	
  “mongodb”)



            ...and Fast
                     (multi-­‐key	
  indexes)

db[“posts”].create_index(“tags”)
Indexing / Querying
     on Embedded Docs
                               (dot	
  notation)

db[“posts”].create_index(“comments.author”)

db[“posts”].find(“comments.author”	
  =>	
  “eliot”)
Counting Posts


db[“posts”].count

db[“posts”].find(:author	
  =>	
  “mike”).count
Basic Paging

page	
  =	
  2
page_size	
  =	
  15

db[“posts”].find.limit(page_size)
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  .skip(page	
  *	
  page_size)
Migration: Adding Titles
                                          (just	
  start	
  adding	
  them)

post	
  =	
  {:author	
  =>	
  “mike”,
	
  	
  	
  	
  	
  	
  	
  	
  :date	
  =>	
  Time.new,
	
  	
  	
  	
  	
  	
  	
  	
  :text	
  =>	
  “another	
  blog	
  post...”,
	
  	
  	
  	
  	
  	
  	
  	
  :tags	
  =>	
  [“mongodb”],
     	
  	
  	
  	
  	
  	
  	
  :title	
  =>	
  “MongoDB	
  for	
  Fun	
  and	
  Profit”}

post_id	
  =	
  db[“posts”].save(post)
Advanced Queries

                   $gt,	
  $lt,	
  $gte,	
  $lte,	
  $ne,	
  $all,	
  $in,	
  $nin
               $not,	
  $mod,	
  $size,	
  $exists,	
  $type,	
  $elemMatch

db[“posts”].find(:$where	
  =>	
  “this.author	
  ==	
  ‘mike’	
  ||
	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  	
  this.title	
  ==	
  ‘foo’”)
MongoMapper,
Mongoid, et. al.
Other Cool Stuff
aggregation	
  and	
  map/reduce
capped	
  collections
unique	
  indexes
mongo	
  shell
GridFS
geo
Download MongoDB
       http://www.mongodb.org




 and	
  let	
  us	
  know	
  what	
  you	
  think
     @mdirolf	
  	
  	
  	
  @mongodb

More Related Content

MongoDB at FrozenRails

  • 1. open-­‐source,  high-­‐performance,   document-­‐oriented  database Mike  Dirolf      •      10gen,  Inc.      •      @mdirolf      •      http://dirolf.com
  • 2. Non-relational Operational Stores (“NoSQL”) New Gen. OLAP RDBMS (vertica,  aster,  greenplum) (Oracle,  MySQL)
  • 3. NoSQL Really Means: non-­‐relational,  next-­‐generation   operational  datastores  and  databases
  • 4. no  joins + no  complex  transactions Horizontally Scalable Architectures
  • 5. no  joins + no  complex  transactions New Data Models
  • 6. New Data Models improved  ways  to  develop  applications?
  • 7. Data Models Key  /  Value memcached,  Dynamo Tabular BigTable Document  Oriented MongoDB,  CouchDB
  • 8. • memcached scalability  &  performance • key/value • RDBMS depth  of  functionality
  • 9. JSON-style Documents represented  as  BSON {“hello”:  “world”} x16x00x00x00x02hello x00x06x00x00x00world x00x00 http://bsonspec.org
  • 10. Flexible “Schemas” {“author”:  “eliot”, {“author”:  “mike”,  “text”:  “...”,  “text”:  “...”}  “tags”:  [“mongodb”]}
  • 12. Atomic Update Modifiers
  • 14. Replication master slave master master slave slave slave slave master master slave master
  • 15. Auto-sharding Shards mongod mongod mongod ... Config mongod mongod mongod Servers mongod mongod mongod mongos mongos ... client
  • 17. Best Use Cases T Scaling  Out Caching The  Web High  Volume
  • 18. Less Good At highly  transactional ad-­‐hoc  business  intelligence problems  that  require  SQL
  • 19. A Quick Aside _id special  key present  in  all  documents unique  across  a  Collection any  type  you  want
  • 20. Post {:author  =>  “mike”,  :date  =>  Time.new,  :text  =>  “my  blog  post...”,  :tags  =>  [“mongodb”,  “ruby”]}
  • 21. Comment {:author  =>  “eliot”,  :date  =>  Time.new,  :text  =>  “great  post!”}
  • 22. New Post post  =  {:author  =>  “mike”,    :date  =>  Time.new,    :text  =>  “my  blog  post...”,    :tags  =>  [“mongodb”,  “ruby”]} db[“posts”].save(post)
  • 23. Embedding a Comment c  =  {:author  =>  “eliot”,    :date  =>  Time.new,    :text  =>  “great  post!”} db[“posts”].update({:_id  =>  post[:_id]},                        {:$push  =>  {:comments  =>  c}})
  • 25. Last 10 Posts db[“posts”].find    .sort([[:date,  :desc]])    .limit(10)
  • 26. Posts Since April 1 april_1  =  Time.utc(2010,  4,  1) db[“posts”].find(:date  =>  {:$gt  =>  april_1})
  • 27. Posts Ending With ‘Ruby’ db[“posts”].find(:text  =>  /Ruby$/)
  • 28. Posts With a Tag db[“posts”].find(:tags  =>  “mongodb”) ...and Fast (multi-­‐key  indexes) db[“posts”].create_index(“tags”)
  • 29. Indexing / Querying on Embedded Docs (dot  notation) db[“posts”].create_index(“comments.author”) db[“posts”].find(“comments.author”  =>  “eliot”)
  • 31. Basic Paging page  =  2 page_size  =  15 db[“posts”].find.limit(page_size)                                .skip(page  *  page_size)
  • 32. Migration: Adding Titles (just  start  adding  them) post  =  {:author  =>  “mike”,                :date  =>  Time.new,                :text  =>  “another  blog  post...”,                :tags  =>  [“mongodb”],              :title  =>  “MongoDB  for  Fun  and  Profit”} post_id  =  db[“posts”].save(post)
  • 33. Advanced Queries $gt,  $lt,  $gte,  $lte,  $ne,  $all,  $in,  $nin $not,  $mod,  $size,  $exists,  $type,  $elemMatch db[“posts”].find(:$where  =>  “this.author  ==  ‘mike’  ||                                                          this.title  ==  ‘foo’”)
  • 35. Other Cool Stuff aggregation  and  map/reduce capped  collections unique  indexes mongo  shell GridFS geo
  • 36. Download MongoDB http://www.mongodb.org and  let  us  know  what  you  think @mdirolf        @mongodb

Editor's Notes

  1. Collection (logical groupings of documents) Indexes are per-collection
  2. blog post twitter