10gen mongodb video presentation at webgeek devcup

30
Scott Hernandez © Copyright 2010 10gen Inc.

Upload: webgeek-philippines

Post on 15-Jan-2015

973 views

Category:

Technology


0 download

DESCRIPTION

Scott Hernandez, Software Engineer, 10gen talks about "Introduction to MongoDB on the Shell"

TRANSCRIPT

Page 1: 10gen MongoDB Video Presentation at WebGeek DevCup

Scott Hernandez

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

Page 2: 10gen MongoDB Video Presentation at WebGeek DevCup

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

Page 3: 10gen MongoDB Video Presentation at WebGeek DevCup

Types of Non-Relational Data Models

•  Key-value stores •  Document stores •  Column-oriented databases •  Graph databases

Page 4: 10gen MongoDB Video Presentation at WebGeek DevCup

What is MongoDB

•  Document Store •  Horizontally Scalable •  High Performance

Page 5: 10gen MongoDB Video Presentation at WebGeek DevCup

MongoDB vs Traditional RDBMS

databases"

contain"rows"

server"

contain"tables""

collections"documents"

schema"

joins"

Page 6: 10gen MongoDB Video Presentation at WebGeek DevCup

Terminology

RDBMS& Mongo&Table,"View" Collection"

Row(s)" JSON"Document"

Index" Index"

Join" Embedded"Document"

Partition" Shard"

Partition"Key" Shard"Key"

Page 7: 10gen MongoDB Video Presentation at WebGeek DevCup

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

Page 8: 10gen MongoDB Video Presentation at WebGeek DevCup

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

Page 9: 10gen MongoDB Video Presentation at WebGeek DevCup

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

Page 10: 10gen MongoDB Video Presentation at WebGeek DevCup

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?

Page 11: 10gen MongoDB Video Presentation at WebGeek DevCup

MongoDB Storage Management

•  Memory-mapped Database files •  Files are (pre)allocated as needed •  Indexes (B*-trees) point to documents

Page 12: 10gen MongoDB Video Presentation at WebGeek DevCup

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)"

Page 13: 10gen MongoDB Video Presentation at WebGeek DevCup

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”]} " "

Page 14: 10gen MongoDB Video Presentation at WebGeek DevCup

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", " ... }"

Page 15: 10gen MongoDB Video Presentation at WebGeek DevCup

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()"

Page 16: 10gen MongoDB Video Presentation at WebGeek DevCup

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} );""

Page 17: 10gen MongoDB Video Presentation at WebGeek DevCup

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"""}"

]}"

Page 18: 10gen MongoDB Video Presentation at WebGeek DevCup

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] } )

Page 19: 10gen MongoDB Video Presentation at WebGeek DevCup

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

Page 20: 10gen MongoDB Video Presentation at WebGeek DevCup

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

Page 21: 10gen MongoDB Video Presentation at WebGeek DevCup

Primary"

Secondary"

Secondary"

Primary"

Secondary"

Secondary"

Primary"

Secondary"

Secondary"

Primary"

Secondary"

Secondary"

Key Range"0..30"

Key Range"31..60"

Key Range"61..90"

Key Range"91.. 100"

MongoS" MongoS" MongoS"

Read"Write"

MongoS"

Page 22: 10gen MongoDB Video Presentation at WebGeek DevCup

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

Page 23: 10gen MongoDB Video Presentation at WebGeek DevCup

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

Page 24: 10gen MongoDB Video Presentation at WebGeek DevCup

@mongodb"

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

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

"

http://bit.ly/mongoQ""

Facebook""""""""""|"""""""""Twitter"""""""""|"""""""""LinkedIn"http://linkd.in/joinmongo"

download at mongodb.org

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

Page 25: 10gen MongoDB Video Presentation at WebGeek DevCup

•  Use cases •  Case studies

Use cases and customers

Page 26: 10gen MongoDB Video Presentation at WebGeek DevCup

Content Management

Page 27: 10gen MongoDB Video Presentation at WebGeek DevCup

Gaming

Page 28: 10gen MongoDB Video Presentation at WebGeek DevCup

Analytics

Page 29: 10gen MongoDB Video Presentation at WebGeek DevCup

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

try at try.mongodb.org

Page 30: 10gen MongoDB Video Presentation at WebGeek DevCup

@mongodb"

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

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

"

http://bit.ly/mongoQ""

Facebook""""""""""|"""""""""Twitter"""""""""|"""""""""LinkedIn"http://linkd.in/joinmongo"

download at mongodb.org

We’re"Hiring"!"[email protected]"

@snanjund"