KEMBAR78
10gen MongoDB Video Presentation at WebGeek DevCup | PDF
Scott Hernandez




 ©"Copyright"2010"10gen"Inc."
Release History
•  First release – February 2009
•  v1.0 - August 2009
•  v1.2 - December 2009 – MapReduce, ++
•  v1.4 - March 2010 – Concurrency, Geo
•  V1.6 - August 2010 – Sharding, Replica Sets
•  V1.8 – March 2011 – Journaling, Geosphere
•  V2.0 -- Sep 2011 – V1 Indexes, Concurrency
Types of Non-Relational Data Models
•  Key-value stores
•  Document stores
•  Column-oriented databases
•  Graph databases
What is MongoDB
•  Document Store
•  Horizontally Scalable
•  High Performance
MongoDB vs Traditional RDBMS
             server"
                              schema"
databases" coll
                  ections
                          "
        contain"tables""
                            documen
                                     ts"
                       contain"rows"
  joins"
Terminology

RDBMS&           Mongo&
Table,"View"     Collection"
Row(s)"          JSON"Document"
Index"           Index"
Join"            Embedded"Document"
Partition"       Shard"
Partition"Key"   Shard"Key"
MongoDB is a Single-Master System
•  All writes are to a primary (master)
•  Failure of the primary is detected, and a new
   one is elected
•  Application writes get an error if there is no
   quorum to elect a new master
  •  Reads can continue
Consistency Models
•  Relational databases support transactions
  •  Can only see committed changes
  •  Commits/aborts span multiple changes
  •  Read-only transaction flavors
    •  Read committed, repeatable read, etc
•  Single vs Multi-Master
Single Master
•  All writes go to a single master and then
   replicated
•  Replication can provide read scalability
•  Writing becomes a bottleneck
  •  Physical limitations (seek time)
  •  Throughput of a single I/O subsystem
Single Master - Sharding
•  Partition the primary key space via hashing
•  Set up a duplicate system for each shard
  •  The write-rate limitation now applies to each
     shard
  •  Joins or aggregation across shards are
     problematic
  •  Can the data be re-sharded on a live system?
  •  Can shards be re-balanced on a live system?
MongoDB Storage Management
•  Memory-mapped Database files
•  Files are (pre)allocated as needed
•  Indexes (B*-trees) point to documents
Documents
Blog Post Document"
"
 p = { author: “sridhar”,"
       date: new Date(),"
       title: “Using the C# driver with MongoDB”,"
       tags: [“NoSQL”, “Mongo”, “MongoDB”]}"
"
> db.posts.save(p)"
Querying
 >db.posts.find()"
"
    { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),"
      author : “sridhar", "
      date : “Mon Jul 11 2011 19:47:11 GMT-0700
(PDT)", "
        title: “Using the C# driver with MongoDB”,"
        tags: [“NoSQL”, “Mongo”, “MongoDB”]} "
  "
Secondary Indexes
Create index on any Field in Document"
"
   // 1 means ascending, -1 means descending"
"
   >db.posts.ensureIndex({author: 1})"
"
   >db.posts.find({author: ʻsridhar'}) "
 "
   { _id     : ObjectId("4c4ba5c0672c685e5e8aabf3"),"
     author : “sridhar", "
     ... }"
Query Operators
•  Conditional Operators "
  •  $all, $exists, $mod, $ne, $in, $nin, $nor, $or, $size, $type"
  •  $lt, $lte, $gt, $gte"
  "
  // find posts with any tags "
  > db.posts.find( {tags: {$exists: true }} )"
  "
  // find posts matching a regular expression"
  > db.posts.find( {author: /^sri*/i } )"
  "
  // count posts by author"
  > db.posts.find( {author: ʻsridharʼ} ).count()"
Atomic Operations
•  $set, $unset, $inc, $push, $pushAll, $pull,
  $pullAll, $bit"

> comment = { author: “fred”, "
              date: new Date(),"
              text: “Interesting blog post”}"
"
 > db.posts.update( { _id: “...” }, "
     "    "$push: {comments: comment} );"
"
Nested Documents

{ _id : ObjectId("4c4ba5c0672c685e5e8aabf3"), "
  author : “sridhar","
  date : “Mon Jul 11 2011 19:47:11 GMT-0700 (PDT)", "
  text : “Using the C# driver with MongoDB","
  tags : [ “NoSQL", “Mongo", “MongoDB" ],"
  comments : ["
       "{"
       "       "author : "Fred","
       "       "date : “Mon Jul 11 2011 20:51:03 GMT-0700 (PDT)","
       "       "text : “Interesting blog post""
       "}"
  ]}"
Indexes
 // Index nested documents
 > db.posts.ensureIndex( “comments.author”:1 )
  !  db.posts.find({‘comments.author’:’Fred’})

 // Index on tags
 > db.posts.ensureIndex( tags: 1)
 > db.posts.find( { tags: ’Mongo’ } )

 // geospatial index
 > db.posts.ensureIndex( “author.location”: “2d” )
 > db.posts.find( “author.location” : { $near : [22,42] } )
MongoDB – More
•  Geo-spatial queries
  •  Require a geo index
  •  Find points near a given point
  •  Find points within a polygon/sphere
•  Built-in Map-Reduce
  •  The caller provides map and reduce functions
    written in JavaScript
Scaling MongoDB
•  Replication - Read scalability
  •  Master/Slave
  •  Replica Sets
•  Sharding – Read and write scalability
  •  Collections are sharded
  •  Each shard is served by its own replica set
  •  Shard key ranges are automatically balanced
Write"       Read"


      MongoS"     MongoS"     MongoS"       MongoS"




 Key Range"      Key Range"    Key Range"       Key Range"
 0..30"          31..60"       61..90"          91.. 100"


 Primary"        Primary"      Primary"         Primary"


Secondary"      Secondary"    Secondary"       Secondary"


Secondary"      Secondary"    Secondary"       Secondary"
MongoDB Access
•  Drivers are available in many languages
  •  10gen supported
     •  C, C# (.Net), C++, Erlang, Haskell, Java,
        JavaScript, Perl, PHP, Python, Ruby, Scala
  •  Community supported
    •  Clojure, ColdFusion, F#, Go, Groovy, Lua, R
    •  http://www.mongodb.org/display/DOCS/Overview+-
       +Writing+Drivers+and+Tools
MongoDB Availability
•  Source
  •  https://github.com/mongodb/mongo
•  Server
  •  License: AGPL
  •  http://www.mongodb.org/downloads
•  Drivers
  •  License: Apache
  •  http://www.mongodb.org/display/DOCS/Drivers
download at mongodb.org

                  We’re"Hiring"!"
       Engineers,"Sales,"Evangelist,"Marketing,"Support,"Developers""

        conferences,"appearances,"and"meetups"
                   http://www.10gen.com/events"
                                "


   Facebook""""""""""|"""""""""Twitter"""""""""|"""""""""LinkedIn"
http://bit.ly/mongoQ""           @mongodb"                  http://linkd.in/joinmongo"



                             ©"Copyright"2010"10gen"Inc."
Use cases and customers
•  Use cases
•  Case studies
Content Management
Gaming
Analytics
try at try.mongodb.org




      ©"Copyright"2010"10gen"Inc."
download at mongodb.org

                     We’re"Hiring"!"
                 sridhar@10gen.com"
                      @snanjund"
        conferences,"appearances,"and"meetups"
                   http://www.10gen.com/events"
                                "


   Facebook""""""""""|"""""""""Twitter"""""""""|"""""""""LinkedIn"
http://bit.ly/mongoQ""        @mongodb"                  http://linkd.in/joinmongo"



                          ©"Copyright"2010"10gen"Inc."

10gen MongoDB Video Presentation at WebGeek DevCup

  • 1.
  • 2.
    Release History •  Firstrelease – February 2009 •  v1.0 - August 2009 •  v1.2 - December 2009 – MapReduce, ++ •  v1.4 - March 2010 – Concurrency, Geo •  V1.6 - August 2010 – Sharding, Replica Sets •  V1.8 – March 2011 – Journaling, Geosphere •  V2.0 -- Sep 2011 – V1 Indexes, Concurrency
  • 3.
    Types of Non-RelationalData Models •  Key-value stores •  Document stores •  Column-oriented databases •  Graph databases
  • 4.
    What is MongoDB • Document Store •  Horizontally Scalable •  High Performance
  • 5.
    MongoDB vs TraditionalRDBMS server" schema" databases" coll ections " contain"tables"" documen ts" contain"rows" joins"
  • 6.
    Terminology RDBMS& Mongo& Table,"View" Collection" Row(s)" JSON"Document" Index" Index" Join" Embedded"Document" Partition" Shard" Partition"Key" Shard"Key"
  • 7.
    MongoDB is aSingle-Master System •  All writes are to a primary (master) •  Failure of the primary is detected, and a new one is elected •  Application writes get an error if there is no quorum to elect a new master •  Reads can continue
  • 8.
    Consistency Models •  Relationaldatabases support transactions •  Can only see committed changes •  Commits/aborts span multiple changes •  Read-only transaction flavors •  Read committed, repeatable read, etc •  Single vs Multi-Master
  • 9.
    Single Master •  Allwrites go to a single master and then replicated •  Replication can provide read scalability •  Writing becomes a bottleneck •  Physical limitations (seek time) •  Throughput of a single I/O subsystem
  • 10.
    Single Master -Sharding •  Partition the primary key space via hashing •  Set up a duplicate system for each shard •  The write-rate limitation now applies to each shard •  Joins or aggregation across shards are problematic •  Can the data be re-sharded on a live system? •  Can shards be re-balanced on a live system?
  • 11.
    MongoDB Storage Management • Memory-mapped Database files •  Files are (pre)allocated as needed •  Indexes (B*-trees) point to documents
  • 12.
    Documents Blog Post Document" " p = { author: “sridhar”," date: new Date()," title: “Using the C# driver with MongoDB”," tags: [“NoSQL”, “Mongo”, “MongoDB”]}" " > db.posts.save(p)"
  • 13.
    Querying >db.posts.find()" " { _id : ObjectId("4c4ba5c0672c685e5e8aabf3")," author : “sridhar", " date : “Mon Jul 11 2011 19:47:11 GMT-0700 (PDT)", " title: “Using the C# driver with MongoDB”," tags: [“NoSQL”, “Mongo”, “MongoDB”]} " "
  • 14.
    Secondary Indexes Create indexon any Field in Document" " // 1 means ascending, -1 means descending" " >db.posts.ensureIndex({author: 1})" " >db.posts.find({author: ʻsridhar'}) " " { _id : ObjectId("4c4ba5c0672c685e5e8aabf3")," author : “sridhar", " ... }"
  • 15.
    Query Operators •  ConditionalOperators " •  $all, $exists, $mod, $ne, $in, $nin, $nor, $or, $size, $type" •  $lt, $lte, $gt, $gte" " // find posts with any tags " > db.posts.find( {tags: {$exists: true }} )" " // find posts matching a regular expression" > db.posts.find( {author: /^sri*/i } )" " // count posts by author" > db.posts.find( {author: ʻsridharʼ} ).count()"
  • 16.
    Atomic Operations •  $set,$unset, $inc, $push, $pushAll, $pull, $pullAll, $bit" > comment = { author: “fred”, " date: new Date()," text: “Interesting blog post”}" " > db.posts.update( { _id: “...” }, " " "$push: {comments: comment} );" "
  • 17.
    Nested Documents { _id: ObjectId("4c4ba5c0672c685e5e8aabf3"), " author : “sridhar"," date : “Mon Jul 11 2011 19:47:11 GMT-0700 (PDT)", " text : “Using the C# driver with MongoDB"," tags : [ “NoSQL", “Mongo", “MongoDB" ]," comments : [" "{" " "author : "Fred"," " "date : “Mon Jul 11 2011 20:51:03 GMT-0700 (PDT)"," " "text : “Interesting blog post"" "}" ]}"
  • 18.
    Indexes // Indexnested documents > db.posts.ensureIndex( “comments.author”:1 ) !  db.posts.find({‘comments.author’:’Fred’}) // Index on tags > db.posts.ensureIndex( tags: 1) > db.posts.find( { tags: ’Mongo’ } ) // geospatial index > db.posts.ensureIndex( “author.location”: “2d” ) > db.posts.find( “author.location” : { $near : [22,42] } )
  • 19.
    MongoDB – More • Geo-spatial queries •  Require a geo index •  Find points near a given point •  Find points within a polygon/sphere •  Built-in Map-Reduce •  The caller provides map and reduce functions written in JavaScript
  • 20.
    Scaling MongoDB •  Replication- Read scalability •  Master/Slave •  Replica Sets •  Sharding – Read and write scalability •  Collections are sharded •  Each shard is served by its own replica set •  Shard key ranges are automatically balanced
  • 21.
    Write" Read" MongoS" MongoS" MongoS" MongoS" Key Range" Key Range" Key Range" Key Range" 0..30" 31..60" 61..90" 91.. 100" Primary" Primary" Primary" Primary" Secondary" Secondary" Secondary" Secondary" Secondary" Secondary" Secondary" Secondary"
  • 22.
    MongoDB Access •  Driversare available in many languages •  10gen supported •  C, C# (.Net), C++, Erlang, Haskell, Java, JavaScript, Perl, PHP, Python, Ruby, Scala •  Community supported •  Clojure, ColdFusion, F#, Go, Groovy, Lua, R •  http://www.mongodb.org/display/DOCS/Overview+- +Writing+Drivers+and+Tools
  • 23.
    MongoDB Availability •  Source •  https://github.com/mongodb/mongo •  Server •  License: AGPL •  http://www.mongodb.org/downloads •  Drivers •  License: Apache •  http://www.mongodb.org/display/DOCS/Drivers
  • 24.
    download at mongodb.org We’re"Hiring"!" Engineers,"Sales,"Evangelist,"Marketing,"Support,"Developers"" conferences,"appearances,"and"meetups" http://www.10gen.com/events" " Facebook""""""""""|"""""""""Twitter"""""""""|"""""""""LinkedIn" http://bit.ly/mongoQ"" @mongodb" http://linkd.in/joinmongo" ©"Copyright"2010"10gen"Inc."
  • 25.
    Use cases andcustomers •  Use cases •  Case studies
  • 26.
  • 27.
  • 28.
  • 29.
    try at try.mongodb.org ©"Copyright"2010"10gen"Inc."
  • 30.
    download at mongodb.org We’re"Hiring"!" sridhar@10gen.com" @snanjund" conferences,"appearances,"and"meetups" http://www.10gen.com/events" " Facebook""""""""""|"""""""""Twitter"""""""""|"""""""""LinkedIn" http://bit.ly/mongoQ"" @mongodb" http://linkd.in/joinmongo" ©"Copyright"2010"10gen"Inc."