MongoDB at RubyEnRails 2009

1,816 views

Published on

Presentation on MongoDB given at RER09. The talk was given on October 31, 2009.

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,816
On SlideShare
0
From Embeds
0
Number of Embeds
4
Actions
Shares
0
Downloads
33
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • Order Preserving Partitioning
    Split
    Migrate
  • Process Diagram

    Global vs Targeted Operations
    Config Servers Use Two Phase Commit
  • Server Layout
  • blog post
    twitter
  • MongoDB at RubyEnRails 2009

    1. 1. open-source, high-performance, schema-free, document-oriented database
    2. 2. RDBMS • Great for many applications • Shortcomings • Scalability • Availability • Flexibility
    3. 3. Key-value stores
    4. 4. CouchDB
    5. 5. JSON-style documents
    6. 6. Schema-free • Loosening constraints - added flexibility • Dynamically typed languages (like Ruby!) • Migrations
    7. 7. Dynamic queries • Administration • Ease of development • Familiarity
    8. 8. Focus on performance
    9. 9. Replication
    10. 10. Auto-sharding
    11. 11. Many supported platforms / languages
    12. 12. Good at • The web • Caching • High volume data • Scalability
    13. 13. Less good at • Highly transactional • Ad-hoc business intelligence • Problems that require SQL
    14. 14. MongoDB Basics
    15. 15. Document • Unit of storage (think row) • BSON (Binary JSON) • Represented as a Hash
    16. 16. Collection • Schema-free equivalent of a table • Logical groups of documents • Indexes are per-collection
    17. 17. _id • Special key • Present in all documents • Unique across a Collection • Any type you want
    18. 18. Blog back-end
    19. 19. Post {:author => "mike", :date => Time.new, :text => "my blog post", :tags => ["mongodb", "ruby", "rer09"]}
    20. 20. Comment {:author => “eliot”, :date => Time.new, :text => “great post!”}
    21. 21. New post post = {:author => "mike", :date => Time.new, :text => "my blog post", :tags => ["mongodb", "ruby", "rer09"]} db[“posts”].save(post)
    22. 22. Embedding a comment c = {:author => “eliot”, :date => Time.new, :text => “great post!”} db[“posts”].update({:_id => post[:_id]}, {:$push => {:comments => c}})
    23. 23. Posts by author db[“posts”].find(:author => “mike”)
    24. 24. Last 10 posts db[“posts”].find .sort([[:date, :desc]]) .limit(10)
    25. 25. Posts in the last week last_week = Time.utc(2009, 10, 24) db[“posts”].find(:date => {:$gt => last_week})
    26. 26. Posts ending with ‘RER’ db[“posts”].find(:text => /RER$/)
    27. 27. Posts with a tag db[“posts”].find(:tags => “mongodb”) ... and fast db[“posts”].create_index(“tags”)
    28. 28. Counting posts db[“posts”].count db[“posts”].find(:author => “mike”).count
    29. 29. Basic paging page = 2 page_size = 15 db[“posts”].find.limit(page_size) .skip(page * page_size)
    30. 30. Migration: adding titles • Easy - just start adding them: post = {:author => “mike”, :date => Time.new, :text => “another blog post”, :tags => [“rer09”], :title => “Review from RER 2009”} post_id = db[“posts”].save(post)
    31. 31. Advanced queries • $gt, $lt, $gte, $lte, $ne, $all, $in, $nin • $where db[“posts”].find :$where => “this.author == ‘mike’ || this.title == ‘hello’”})
    32. 32. MongoMapper, Mongoid, MongoRecord, etc.
    33. 33. MongoMapper class User include MongoMapper::Document many :posts end class Post include MongoMapper::Document key :user_id, String key :title, String end user = User.create user.posts.create(:title => 'Foo') # would return post we just created user.posts.find_by_title('Foo')
    34. 34. Other cool stuff • Aggregation and map reduce • Capped collections • Unique indexes • Mongo shell • GridFS
    35. 35. Sharding
    36. 36. 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
    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

    ×