Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
open-source, high-performance,
schema-free, document-oriented
           database
RDBMS

• Great for many applications
• Shortcomings
 • Scalability
 • Flexibility
CAP theorem

• Consistency
• Availability
• Tolerance to network Partitions
• Pick two

       http://www.cs.berkeley.edu/...
ACID vs BASE

•   Atomicity
                  •   Basically Available
•   Consistency
                  •   Soft state
•  ...
Compared to key-value
      stores
Compared to
 CouchDB
JSON-style documents
Schema-free

• Loosening constraints - added flexibility
• Dynamically typed languages
• Migrations
Dynamic queries

• Administration
• Ease of development
• Familiarity
Focus on performance
Replication
Auto-sharding
Many supported
platforms / languages
Good at

• The web
• Caching
• High volume data
• Scalability
Less good at

• Highly transactional
• Ad-hoc business intelligence
• Problems that require SQL
MongoDB Basics
Document


• Unit of storage (think row)
• BSON (Binary JSON)
Collection

• Schema-free equivalent of a table
• Logical groups of documents
• Indexes are per-collection
_id

• Special key
• Present in all documents
• Unique across a Collection
• Any type you want
Blog back-end
Post

{author: “mike”,
 date: new Date(),
 text: “my blog post...”,
 tags: [“mongodb”, “strange”, “loop”]}
Comment


{author: “eliot”,
 date: new Date(),
 text: “great post!”}
New post

post = {author: “mike”,
  date: new Date(),
  text: “my blog post...”,
  tags: [“mongodb”, “strange”, “loop”]}

...
Embedding a comment

c = {author: “eliot”,
  date: new Date(),
  text: “great post!”}

db.posts.update({_id: post._id},
  ...
Posts by author


db.posts.find({author: “mike”})
Last 10 posts

db.posts.find()
        .sort({date: -1})
        .limit(10)
Posts in the last week


last_week = new Date(2009, 9, 9)

db.posts.find({date: {$gt: last_week}})
Posts ending with
          ‘Loop’


db.posts.find({text: /loop$/})
Posts with a tag
db.posts.find({tag: “mongodb”})




          ... and fast
db.posts.ensureIndex({tag: 1})
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
  • Easy - just start adding them:
post = {author: “mike”,
        date: new Date(),
        text...
Advanced queries


    • $gt, $lt, $gte, $lte, $ne, $all, $in, $nin
    • where()
db.posts.find({$where: “this.author == ‘...
Sharding
Terminology
• Shard key
• Chunk
 • Range of the value space
 • (collection, key, min_val, max_val)
• Shard
 • Single node ...
Other cool stuff

• Aggregation and map reduce
• Capped collections
• Unique indexes
• Mongo shell
• GridFS
• Download MongoDB
  http://www.mongodb.org

• Try it out
• Let us know what you think!
• http://www.mongodb.org
• irc.freenode.net#mongodb
• mongodb-user on google groups
• @mongodb, @mdirolf
• mike@10gen.com
...
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009
MongoDB Strange Loop 2009
Upcoming SlideShare
Loading in …5
×

MongoDB Strange Loop 2009

3,040 views

Published on

Talk on MongoDB given at the first Strange Loop Conference in St. Louis, October 2009.

Published in: Technology
  • Be the first to comment

MongoDB Strange Loop 2009

  1. 1. open-source, high-performance, schema-free, document-oriented database
  2. 2. RDBMS • Great for many applications • Shortcomings • Scalability • Flexibility
  3. 3. CAP theorem • Consistency • Availability • Tolerance to network Partitions • Pick two http://www.cs.berkeley.edu/~brewer/cs262b-2004/PODC-keynote.pdf
  4. 4. ACID vs BASE • Atomicity • Basically Available • Consistency • Soft state • Isolation • Eventually consistent • Durability
  5. 5. Compared to key-value stores
  6. 6. Compared to CouchDB
  7. 7. JSON-style documents
  8. 8. Schema-free • Loosening constraints - added flexibility • Dynamically typed languages • Migrations
  9. 9. Dynamic queries • Administration • Ease of development • Familiarity
  10. 10. Focus on performance
  11. 11. Replication
  12. 12. Auto-sharding
  13. 13. Many supported platforms / languages
  14. 14. Good at • The web • Caching • High volume data • Scalability
  15. 15. Less good at • Highly transactional • Ad-hoc business intelligence • Problems that require SQL
  16. 16. MongoDB Basics
  17. 17. Document • Unit of storage (think row) • BSON (Binary JSON)
  18. 18. Collection • Schema-free equivalent of a table • Logical groups of documents • Indexes are per-collection
  19. 19. _id • Special key • Present in all documents • Unique across a Collection • Any type you want
  20. 20. Blog back-end
  21. 21. Post {author: “mike”, date: new Date(), text: “my blog post...”, tags: [“mongodb”, “strange”, “loop”]}
  22. 22. Comment {author: “eliot”, date: new Date(), text: “great post!”}
  23. 23. New post post = {author: “mike”, date: new Date(), text: “my blog post...”, tags: [“mongodb”, “strange”, “loop”]} db.posts.save(post)
  24. 24. Embedding a comment c = {author: “eliot”, date: new Date(), text: “great post!”} db.posts.update({_id: post._id}, {$push: {comments: c}})
  25. 25. Posts by author db.posts.find({author: “mike”})
  26. 26. Last 10 posts db.posts.find() .sort({date: -1}) .limit(10)
  27. 27. Posts in the last week last_week = new Date(2009, 9, 9) db.posts.find({date: {$gt: last_week}})
  28. 28. Posts ending with ‘Loop’ db.posts.find({text: /loop$/})
  29. 29. Posts with a tag db.posts.find({tag: “mongodb”}) ... and fast db.posts.ensureIndex({tag: 1})
  30. 30. Counting posts db.posts.count() db.posts.find({author: “mike”}).count()
  31. 31. Basic paging page = 2 page_size = 15 db.posts.find().limit(page_size) .skip(page * page_size)
  32. 32. Migration: adding titles • Easy - just start adding them: post = {author: “mike”, date: new Date(), text: “another blog post...”, tags: [“strange”, “loop”], title: “Review from Strange Loop”} post_id = db.posts.save(post)
  33. 33. Advanced queries • $gt, $lt, $gte, $lte, $ne, $all, $in, $nin • where() db.posts.find({$where: “this.author == ‘mike’”})
  34. 34. Sharding
  35. 35. Terminology • Shard key • Chunk • Range of the value space • (collection, key, min_val, max_val) • Shard • Single node (or replica pair) • Responsible for set of chunks
  36. 36. Other cool stuff • Aggregation and map reduce • Capped collections • Unique indexes • Mongo shell • GridFS
  37. 37. • Download MongoDB http://www.mongodb.org • Try it out • Let us know what you think!
  38. 38. • http://www.mongodb.org • irc.freenode.net#mongodb • mongodb-user on google groups • @mongodb, @mdirolf • mike@10gen.com • http://www.slideshare.net/mdirolf

×