Mongodb railscamphh

1,110
-1

Published on

Published in: Technology
0 Comments
1 Like
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total Views
1,110
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
6
Comments
0
Likes
1
Embeds 0
No embeds

No notes for slide

Mongodb railscamphh

  1. 1. on rails railscamp hamburg, 2010 jan krutisch <jan@krutisch.de> http://jan.krutisch.de/ Samstag, 23. Oktober 2010
  2. 2. mongodb wtf? lol!? Samstag, 23. Oktober 2010
  3. 3. document database Samstag, 23. Oktober 2010
  4. 4. document database NoSQLincluded! Samstag, 23. Oktober 2010
  5. 5. 10gen Samstag, 23. Oktober 2010
  6. 6. open source http://github.com/mongodb/mongo Samstag, 23. Oktober 2010
  7. 7. id title descr pos_lat pos_lng Samstag, 23. Oktober 2010
  8. 8. { "_id" : ObjectId("4c00245062610475a005afcd"), "address" : "Bernstorffstr. 174n22767 HamburgnDE", "description" : null, "position" : { "lat" : 53.5600912, "lng" : 9.9596977 }, "tags" : [ "hausarzt", "naturheilverfahren", "akupunktur", "allgemeinmedizin" ], "title" : "Dr. med. Lilo Eisenbarth", "loxicon_id" : 808261 } Samstag, 23. Oktober 2010
  9. 9. Samstag, 23. Oktober 2010
  10. 10. ✗Samstag, 23. Oktober 2010
  11. 11. Samstag, 23. Oktober 2010
  12. 12. BSON Samstag, 23. Oktober 2010
  13. 13. BInary Serialized jsON http://bsonspec.org/ Samstag, 23. Oktober 2010
  14. 14. Wire Samstag, 23. Oktober 2010
  15. 15. Storage Samstag, 23. Oktober 2010
  16. 16. rich queries Samstag, 23. Oktober 2010
  17. 17. conceptually close to SQL Samstag, 23. Oktober 2010
  18. 18. easy to grasp Samstag, 23. Oktober 2010
  19. 19. flexible Samstag, 23. Oktober 2010
  20. 20. language integration Samstag, 23. Oktober 2010
  21. 21. on top: map/reduce Samstag, 23. Oktober 2010
  22. 22. Scaling Samstag, 23. Oktober 2010
  23. 23. Master/Slave replication Samstag, 23. Oktober 2010
  24. 24. Replica Sets (1.6) Samstag, 23. Oktober 2010
  25. 25. Primary Member Member Samstag, 23. Oktober 2010
  26. 26. Primary Member Primary Samstag, 23. Oktober 2010
  27. 27. Member Member Primary Samstag, 23. Oktober 2010
  28. 28. Autosharding (1.6) Samstag, 23. Oktober 2010
  29. 29. Samstag, 23. Oktober 2010
  30. 30. Durability Samstag, 23. Oktober 2010
  31. 31. No single server durability! Samstag, 23. Oktober 2010
  32. 32. fsyncs every 60s (configurable) Samstag, 23. Oktober 2010
  33. 33. Use Replication! Samstag, 23. Oktober 2010
  34. 34. Use write propagation locking Samstag, 23. Oktober 2010
  35. 35. Single Server Durability planned for 1.8 Samstag, 23. Oktober 2010
  36. 36. mongo console Samstag, 23. Oktober 2010
  37. 37. $ mongo Samstag, 23. Oktober 2010
  38. 38. > use test switched to db test db.quotes.save({ text: "You can observe a lot just by watching.", from: "Yogi Berra", created_at: new Date() }); db.quotes.save({ text: "Silence is one of the hardest arguments to refute.", from: "Josh Billings", created_at: new Date() }); Samstag, 23. Oktober 2010
  39. 39. > use test switched to db test db.quotes.save({ text: "You can observe a lot just by watching.", from: "Yogi Berra", created_at: new Date() }); db.quotes.save({ text: "Silence is one of the hardest arguments to refute.", from: "Josh Billings", created_at: new Date() }); Samstag, 23. Oktober 2010
  40. 40. Indexing Samstag, 23. Oktober 2010
  41. 41. Same concept as with SQL databases Samstag, 23. Oktober 2010
  42. 42. You want them Samstag, 23. Oktober 2010
  43. 43. Same concept as with SQL databases Samstag, 23. Oktober 2010
  44. 44. Sort order Samstag, 23. Oktober 2010
  45. 45. Unique Samstag, 23. Oktober 2010
  46. 46. Compound Samstag, 23. Oktober 2010
  47. 47. Geospatial Samstag, 23. Oktober 2010
  48. 48. map/reduce Samstag, 23. Oktober 2010
  49. 49. we can haz it, too Samstag, 23. Oktober 2010
  50. 50. function() { this.tags.forEach(function(z) { emit(z, {count: 1}); }); } Samstag, 23. Oktober 2010
  51. 51. function(key, values) { var total = 0; values.forEach(function(v) { total += v.count }); return {count: total} } Samstag, 23. Oktober 2010
  52. 52. (it‘s not fast...) Samstag, 23. Oktober 2010
  53. 53. security Samstag, 23. Oktober 2010
  54. 54. simple user/password auth Samstag, 23. Oktober 2010
  55. 55. per database Samstag, 23. Oktober 2010
  56. 56. read only is possible Samstag, 23. Oktober 2010
  57. 57. one more thing Samstag, 23. Oktober 2010
  58. 58. GridFS Samstag, 23. Oktober 2010
  59. 59. Binary fields in BSON < 4MB Samstag, 23. Oktober 2010
  60. 60. GridFS saves files in chunks Samstag, 23. Oktober 2010
  61. 61. I‘m in u‘r rubies, querying teh MongoDB! Samstag, 23. Oktober 2010
  62. 62. core driver Samstag, 23. Oktober 2010
  63. 63. mongo / bson_ext Samstag, 23. Oktober 2010
  64. 64. ODMs / Libs Samstag, 23. Oktober 2010
  65. 65. mongo_mapper Samstag, 23. Oktober 2010
  66. 66. mongoid Samstag, 23. Oktober 2010
  67. 67. Find examples here: http://github.com/halfbyte/mongo_ruby_examples Samstag, 23. Oktober 2010
  68. 68. Basic driver usage Samstag, 23. Oktober 2010
  69. 69. init Samstag, 23. Oktober 2010
  70. 70. require 'mongo' @connection = Mongo::Connection.new @db = @connection.db("test") Samstag, 23. Oktober 2010
  71. 71. @connection = Mongo::Connection.new( 'localhost', 27017, :pool_size => 5, :timeout => 20 ) Samstag, 23. Oktober 2010
  72. 72. @connection = Mongo::Connection.from_uri( "mongodb://localhost:27017/test" ) Samstag, 23. Oktober 2010
  73. 73. insert/upsert Samstag, 23. Oktober 2010
  74. 74. doc = { :text => "You can observe a lot just by watching.", :from => "Yogi Berra", :created_at => Time.now } @db['quotes'].insert(doc) Samstag, 23. Oktober 2010
  75. 75. doc = @db['quotes'].find_one(id) doc[:from] = "Yogi Berra, famous baseball player" @db['quotes'].save(doc) Samstag, 23. Oktober 2010
  76. 76. atomic updates Samstag, 23. Oktober 2010
  77. 77. @db['quotes'].update( {"from" => "Yogi Berra"}, {"$inc" => {"reads" => 1 } } ) Samstag, 23. Oktober 2010
  78. 78. @db['quotes'].update( {"from" => "Yogi Berra"}, {"$inc" => {"reads" => 1 } } ) Samstag, 23. Oktober 2010
  79. 79. $inc $set $unset $push $pushAll $addToSet $pop $pull $pullAll $ Samstag, 23. Oktober 2010
  80. 80. getting a whole collection Samstag, 23. Oktober 2010
  81. 81. @db['quotes'].find.each do |row| puts row.inspect end Samstag, 23. Oktober 2010
  82. 82. exact query Samstag, 23. Oktober 2010
  83. 83. @db['quotes'].find(:from => "Yogi Berra") Samstag, 23. Oktober 2010
  84. 84. more queries Samstag, 23. Oktober 2010
  85. 85. 100.times do |i| db['numbers'].insert({"i" => i}) end Samstag, 23. Oktober 2010
  86. 86. db['numbers'].find("i" => {"$lt" => 2}) Samstag, 23. Oktober 2010
  87. 87. $lt < $gt > $lte <= $gte >= $ne != Samstag, 23. Oktober 2010
  88. 88. @db['people'].find(:tags => {"$in" => ['cool']}) Samstag, 23. Oktober 2010
  89. 89. obj = { "_id"=>BSON::ObjectID('4c706af16261040680000369'), "name"=>"Vernon Kreiger", "address"=>{ "street"=>"536 Haleigh Locks", "city"=>"Port Kiannahaven", "zip"=>"80730-0214", "country"=>"Fakistan" }, "tags"=>["cool", "weird"] } Samstag, 23. Oktober 2010
  90. 90. obj = { "_id"=>BSON::ObjectID('4c706af16261040680000369'), "name"=>"Vernon Kreiger", "address"=>{ "street"=>"536 Haleigh Locks", "city"=>"Port Kiannahaven", "zip"=>"80730-0214", "country"=>"Fakistan" }, "tags"=>["cool", "weird"] } Samstag, 23. Oktober 2010
  91. 91. $in IN (2,3,4) $nin NOT IN $all [2,3] ~ [1,2,3] Samstag, 23. Oktober 2010
  92. 92. $mod yah, RLY $size okay $exists NOT NULL $type huh? Samstag, 23. Oktober 2010
  93. 93. @db['people'].find("address.city" => /haven/) Samstag, 23. Oktober 2010
  94. 94. @db['people'].find("address.city" => /haven/) Samstag, 23. Oktober 2010
  95. 95. Sorting Samstag, 23. Oktober 2010
  96. 96. @db['people'].find().sort("address.street") Samstag, 23. Oktober 2010
  97. 97. @db['people'].find().sort("address.street") Samstag, 23. Oktober 2010
  98. 98. Pagination Samstag, 23. Oktober 2010
  99. 99. @db['numbers'].find.sort("i").limit(10) Samstag, 23. Oktober 2010
  100. 100. @db['numbers'].find.sort("i").limit(10).skip(50) Samstag, 23. Oktober 2010
  101. 101. Counting Samstag, 23. Oktober 2010
  102. 102. @db['numbers'].find.count Samstag, 23. Oktober 2010
  103. 103. Distinct Samstag, 23. Oktober 2010
  104. 104. @db['people'].distinct('tags').inspect Samstag, 23. Oktober 2010
  105. 105. Group Samstag, 23. Oktober 2010
  106. 106. Poor mans map/reduce Samstag, 23. Oktober 2010
  107. 107. @db['people'].group( ['created_at'], {}, {:tags => {}}, reduce, finalize ) Samstag, 23. Oktober 2010
  108. 108. @db['people'].group( ['created_at'], {}, {:tags => {}}, reduce, finalize ) Samstag, 23. Oktober 2010
  109. 109. @db['people'].group( ['created_at'], {}, {:tags => {}}, reduce, finalize ) Samstag, 23. Oktober 2010
  110. 110. @db['people'].group( ['created_at'], {}, {:tags => {}}, reduce, finalize ) Samstag, 23. Oktober 2010
  111. 111. @db['people'].group( ['created_at'], {}, {:tags => {}}, reduce, finalize ) Samstag, 23. Oktober 2010
  112. 112. function(doc, prev) { for(i in doc.tags) { if (doc.tags[i] in prev.tags) { prev.tags[doc.tags[i]]++ } else { prev.tags[doc.tags[i]] =1 } } } Samstag, 23. Oktober 2010
  113. 113. {"created_at"=>2010-09-19 22:00:00 UTC, "tags"=>{"foo"=>11.0, "dumb"=>12.0, "stupid"=>7.0, "bar"=>7.0, "cool"=>14.0, "weird"=>17.0}} {"created_at"=>2010-09-20 22:00:00 UTC, "tags"=>{"dumb"=>11.0, "stupid"=>5.0, "foo"=>10.0, "cool"=>8.0, "weird"=>9.0, "bar"=>15.0}} {"created_at"=>2010-09-22 22:00:00 UTC, "tags"=>{"weird"=>15.0, "bar"=>9.0, "stupid"=>17.0, "cool"=>11.0, "dumb"=>10.0, "foo"=>12.0}} {"created_at"=>2010-09-15 22:00:00 UTC, "tags"=>{"foo"=>11.0, "weird"=>7.0, "stupid"=>10.0, "cool"=>11.0, "bar"=>5.0, "dumb"=>8.0}} {"created_at"=>2010-09-25 22:00:00 UTC, "tags"=>{"dumb"=>11.0, "weird"=>14.0, "cool"=>8.0, "foo"=>21.0, "bar"=>11.0, "stupid"=>13.0}} {"created_at"=>2010-09-28 22:00:00 UTC, "tags"=>{"cool"=>11.0, "dumb"=>16.0, "stupid"=>11.0, "weird"=>15.0, "foo"=>9.0, "bar"=>16.0}} {"created_at"=>2010-09-10 22:00:00 UTC, "tags"=>{"dumb"=>15.0, "weird"=>9.0, "bar"=>8.0, "cool"=>14.0, "stupid"=>11.0, "foo"=>11.0}} {"created_at"=>2010-09-03 22:00:00 UTC, "tags"=>{"weird"=>14.0, "dumb"=>15.0, "stupid"=>11.0, "foo"=>16.0, "bar"=>20.0, "cool"=>10.0}} {"created_at"=>2010-09-21 22:00:00 UTC, "tags"=>{"weird"=>15.0, "cool"=>14.0, "foo"=>13.0, "stupid"=>6.0, "bar"=>11.0, "dumb"=>9.0}} {"created_at"=>2010-09-23 22:00:00 UTC, "tags"=>{"weird"=>15.0, "stupid"=>15.0, "dumb"=>15.0, "foo"=>16.0, "cool"=>10.0, "bar"=>11.0}} {"created_at"=>2010-09-29 22:00:00 UTC, "tags"=>{"bar"=>9.0, "cool"=>14.0, "weird"=>16.0, "foo"=>8.0, "dumb"=>9.0, "stupid"=>12.0}} {"created_at"=>2010-09-27 22:00:00 UTC, "tags"=>{"cool"=>13.0, "dumb"=>10.0, "stupid"=>12.0, "bar"=>8.0, "foo"=>16.0, "weird"=>13.0}} {"created_at"=>2010-09-04 22:00:00 UTC, "tags"=>{"cool"=>11.0, "bar"=>9.0, "stupid"=>6.0, "weird"=>11.0, "dumb"=>8.0, "foo"=>11.0}} {"created_at"=>2010-09-08 22:00:00 UTC, "tags"=>{"stupid"=>12.0, "dumb"=>11.0, "cool"=>15.0, "foo"=>11.0, "bar"=>9.0, "weird"=>8.0}} {"created_at"=>2010-10-02 22:00:00 UTC, "tags"=>{"bar"=>8.0, "dumb"=>8.0, "cool"=>10.0, "foo"=>10.0, "stupid"=>8.0, "weird"=>6.0}} {"created_at"=>2010-09-24 22:00:00 UTC, "tags"=>{"foo"=>13.0, "bar"=>12.0, "stupid"=>15.0, "weird"=>17.0, "dumb"=>7.0, "cool"=>10.0}} {"created_at"=>2010-09-30 22:00:00 UTC, "tags"=>{"bar"=>10.0, "cool"=>6.0, "stupid"=>14.0, "weird"=>9.0, "dumb"=>12.0, "foo"=>19.0}} {"created_at"=>2010-09-05 22:00:00 UTC, "tags"=>{"dumb"=>12.0, "foo"=>19.0, "weird"=>8.0, "stupid"=>8.0, "bar"=>7.0, "cool"=>10.0}} {"created_at"=>2010-09-17 22:00:00 UTC, "tags"=>{"weird"=>13.0, "bar"=>14.0, "dumb"=>12.0, "foo"=>12.0, "stupid"=>10.0, "cool"=>9.0}} {"created_at"=>2010-09-18 22:00:00 UTC, "tags"=>{"dumb"=>8.0, "cool"=>11.0, "foo"=>6.0, "bar"=>12.0, "weird"=>7.0, "stupid"=>6.0}} {"created_at"=>2010-09-09 22:00:00 UTC, "tags"=>{"weird"=>11.0, "dumb"=>9.0, "foo"=>6.0, "bar"=>11.0, "cool"=>11.0, "stupid"=>6.0}} {"created_at"=>2010-09-13 22:00:00 UTC, "tags"=>{"dumb"=>19.0, "stupid"=>9.0, "weird"=>12.0, "cool"=>11.0, "bar"=>10.0, "foo"=>15.0}} {"created_at"=>2010-09-16 22:00:00 UTC, "tags"=>{"bar"=>6.0, "weird"=>8.0, "dumb"=>9.0, "cool"=>11.0, "stupid"=>17.0, "foo"=>15.0}} {"created_at"=>2010-09-11 22:00:00 UTC, "tags"=>{"foo"=>10.0, "weird"=>9.0, "bar"=>8.0, "cool"=>4.0, "dumb"=>8.0, "stupid"=>9.0}} {"created_at"=>2010-09-26 22:00:00 UTC, "tags"=>{"dumb"=>15.0, "weird"=>6.0, "stupid"=>15.0, "bar"=>10.0, "foo"=>13.0, "cool"=>15.0}} {"created_at"=>2010-10-01 22:00:00 UTC, "tags"=>{"cool"=>7.0, "weird"=>11.0, "stupid"=>11.0, "bar"=>14.0, "foo"=>12.0, "dumb"=>11.0}} {"created_at"=>2010-09-12 22:00:00 UTC, "tags"=>{"bar"=>7.0, "weird"=>12.0, "stupid"=>11.0, "cool"=>10.0, "foo"=>11.0, "dumb"=>9.0}} {"created_at"=>2010-09-14 22:00:00 UTC, "tags"=>{"dumb"=>8.0, "foo"=>15.0, "cool"=>15.0, "stupid"=>15.0, "bar"=>7.0, "weird"=>14.0}} {"created_at"=>2010-09-07 22:00:00 UTC, "tags"=>{"dumb"=>10.0, "cool"=>7.0, "foo"=>14.0, "weird"=>15.0, "bar"=>11.0, "stupid"=>7.0}} {"created_at"=>2010-09-06 22:00:00 UTC, "tags"=>{"dumb"=>7.0, "bar"=>11.0, "cool"=>16.0, "weird"=>14.0, "foo"=>12.0, "stupid"=>6.0}} Samstag, 23. Oktober 2010
  114. 114. {"created_at"=>2010-09-19 22:00:00 UTC, "tags"=>{"foo"=>11.0, "dumb"=>12.0, "stupid"=>7.0, "bar"=>7.0, "cool"=>14.0, "weird"=>17.0}} {"created_at"=>2010-09-20 22:00:00 UTC, "tags"=>{"dumb"=>11.0, "stupid"=>5.0, "foo"=>10.0, "cool"=>8.0, "weird"=>9.0, "bar"=>15.0}} {"created_at"=>2010-09-22 22:00:00 UTC, "tags"=>{"weird"=>15.0, "bar"=>9.0, "stupid"=>17.0, "cool"=>11.0, "dumb"=>10.0, "foo"=>12.0}} {"created_at"=>2010-09-15 22:00:00 UTC, "tags"=>{"foo"=>11.0, "weird"=>7.0, "stupid"=>10.0, "cool"=>11.0, "bar"=>5.0, "dumb"=>8.0}} {"created_at"=>2010-09-25 22:00:00 UTC, "tags"=>{"dumb"=>11.0, "weird"=>14.0, "cool"=>8.0, "foo"=>21.0, "bar"=>11.0, "stupid"=>13.0}} {"created_at"=>2010-09-28 22:00:00 UTC, "tags"=>{"cool"=>11.0, "dumb"=>16.0, "stupid"=>11.0, "weird"=>15.0, "foo"=>9.0, "bar"=>16.0}} {"created_at"=>2010-09-10 22:00:00 UTC, "tags"=>{"dumb"=>15.0, "weird"=>9.0, "bar"=>8.0, "cool"=>14.0, "stupid"=>11.0, "foo"=>11.0}} {"created_at"=>2010-09-03 22:00:00 UTC, "tags"=>{"weird"=>14.0, "dumb"=>15.0, "stupid"=>11.0, "foo"=>16.0, "bar"=>20.0, "cool"=>10.0}} {"created_at"=>2010-09-21 22:00:00 UTC, "tags"=>{"weird"=>15.0, "cool"=>14.0, "foo"=>13.0, "stupid"=>6.0, "bar"=>11.0, "dumb"=>9.0}} {"created_at"=>2010-09-23 22:00:00 UTC, "tags"=>{"weird"=>15.0, "stupid"=>15.0, "dumb"=>15.0, "foo"=>16.0, "cool"=>10.0, "bar"=>11.0}} {"created_at"=>2010-09-29 22:00:00 UTC, "tags"=>{"bar"=>9.0, "cool"=>14.0, "weird"=>16.0, "foo"=>8.0, "dumb"=>9.0, "stupid"=>12.0}} {"created_at"=>2010-09-27 22:00:00 UTC, "tags"=>{"cool"=>13.0, "dumb"=>10.0, "stupid"=>12.0, "bar"=>8.0, "foo"=>16.0, "weird"=>13.0}} {"created_at"=>2010-09-04 22:00:00 UTC, "tags"=>{"cool"=>11.0, "bar"=>9.0, "stupid"=>6.0, "weird"=>11.0, "dumb"=>8.0, "foo"=>11.0}} {"created_at"=>2010-09-08 22:00:00 UTC, "tags"=>{"stupid"=>12.0, "dumb"=>11.0, "cool"=>15.0, "foo"=>11.0, "bar"=>9.0, "weird"=>8.0}} {"created_at"=>2010-10-02 22:00:00 UTC, "tags"=>{"bar"=>8.0, "dumb"=>8.0, "cool"=>10.0, "foo"=>10.0, "stupid"=>8.0, "weird"=>6.0}} {"created_at"=>2010-09-24 22:00:00 UTC, "tags"=>{"foo"=>13.0, "bar"=>12.0, "stupid"=>15.0, "weird"=>17.0, "dumb"=>7.0, "cool"=>10.0}} {"created_at"=>2010-09-30 22:00:00 UTC, "tags"=>{"bar"=>10.0, "cool"=>6.0, "stupid"=>14.0, "weird"=>9.0, "dumb"=>12.0, "foo"=>19.0}} {"created_at"=>2010-09-05 22:00:00 UTC, "tags"=>{"dumb"=>12.0, "foo"=>19.0, "weird"=>8.0, "stupid"=>8.0, "bar"=>7.0, "cool"=>10.0}} {"created_at"=>2010-09-17 22:00:00 UTC, "tags"=>{"weird"=>13.0, "bar"=>14.0, "dumb"=>12.0, "foo"=>12.0, "stupid"=>10.0, "cool"=>9.0}} {"created_at"=>2010-09-18 22:00:00 UTC, "tags"=>{"dumb"=>8.0, "cool"=>11.0, "foo"=>6.0, "bar"=>12.0, "weird"=>7.0, "stupid"=>6.0}} {"created_at"=>2010-09-09 22:00:00 UTC, "tags"=>{"weird"=>11.0, "dumb"=>9.0, "foo"=>6.0, "bar"=>11.0, "cool"=>11.0, "stupid"=>6.0}} {"created_at"=>2010-09-13 22:00:00 UTC, "tags"=>{"dumb"=>19.0, "stupid"=>9.0, "weird"=>12.0, "cool"=>11.0, "bar"=>10.0, "foo"=>15.0}} {"created_at"=>2010-09-16 22:00:00 UTC, "tags"=>{"bar"=>6.0, "weird"=>8.0, "dumb"=>9.0, "cool"=>11.0, "stupid"=>17.0, "foo"=>15.0}} {"created_at"=>2010-09-11 22:00:00 UTC, "tags"=>{"foo"=>10.0, "weird"=>9.0, "bar"=>8.0, "cool"=>4.0, "dumb"=>8.0, "stupid"=>9.0}} {"created_at"=>2010-09-26 22:00:00 UTC, "tags"=>{"dumb"=>15.0, "weird"=>6.0, "stupid"=>15.0, "bar"=>10.0, "foo"=>13.0, "cool"=>15.0}} {"created_at"=>2010-10-01 22:00:00 UTC, "tags"=>{"cool"=>7.0, "weird"=>11.0, "stupid"=>11.0, "bar"=>14.0, "foo"=>12.0, "dumb"=>11.0}} {"created_at"=>2010-09-12 22:00:00 UTC, "tags"=>{"bar"=>7.0, "weird"=>12.0, "stupid"=>11.0, "cool"=>10.0, "foo"=>11.0, "dumb"=>9.0}} {"created_at"=>2010-09-14 22:00:00 UTC, "tags"=>{"dumb"=>8.0, "foo"=>15.0, "cool"=>15.0, "stupid"=>15.0, "bar"=>7.0, "weird"=>14.0}} {"created_at"=>2010-09-07 22:00:00 UTC, "tags"=>{"dumb"=>10.0, "cool"=>7.0, "foo"=>14.0, "weird"=>15.0, "bar"=>11.0, "stupid"=>7.0}} {"created_at"=>2010-09-06 22:00:00 UTC, "tags"=>{"dumb"=>7.0, "bar"=>11.0, "cool"=>16.0, "weird"=>14.0, "foo"=>12.0, "stupid"=>6.0}} "tags" => { "foo" => 11.0, "dumb" => 12.0, "stupid" => 7.0, "bar" => 7.0, "cool" => 14.0, "weird" => 17.0 } Samstag, 23. Oktober 2010
  115. 115. function(prev) { var mostPopular = 0; for(i in prev.tags) { if(prev.tags[i] > mostPopular) { prev.tag = i; prev.count = prev.tags[i]; mostPopular = prev.tags[i]; } } delete prev.tags } Samstag, 23. Oktober 2010
  116. 116. {"created_at"=>2010-09-27 22:00:00 UTC, "tag"=>"stupid", "count"=>18.0} {"created_at"=>2010-09-29 22:00:00 UTC, "tag"=>"stupid", "count"=>20.0} {"created_at"=>2010-09-12 22:00:00 UTC, "tag"=>"cool", "count"=>11.0} {"created_at"=>2010-09-04 22:00:00 UTC, "tag"=>"stupid", "count"=>12.0} {"created_at"=>2010-09-21 22:00:00 UTC, "tag"=>"stupid", "count"=>16.0} {"created_at"=>2010-09-03 22:00:00 UTC, "tag"=>"foo", "count"=>15.0} {"created_at"=>2010-09-26 22:00:00 UTC, "tag"=>"foo", "count"=>17.0} {"created_at"=>2010-09-18 22:00:00 UTC, "tag"=>"foo", "count"=>17.0} {"created_at"=>2010-09-24 22:00:00 UTC, "tag"=>"cool", "count"=>11.0} Samstag, 23. Oktober 2010
  117. 117. Map / Reduce Samstag, 23. Oktober 2010
  118. 118. map = <<-END function() { this.tags.forEach(function(z) { emit(z, {count: 1}); }); } END reduce = <<-END function(key, values) { var total = 0; values.forEach(function(v) { total += v.count }); return {count: total} } END collection = @db['people'].map_reduce( map, reduce ) Samstag, 23. Oktober 2010
  119. 119. Indexes Samstag, 23. Oktober 2010
  120. 120. db['people'].create_index("tags") @db['people'].create_index( [["tags", Mongo::ASCENDING]] ) db['people'].drop_index("tags_1") db['people'].drop_indexes db['people'].index_information Samstag, 23. Oktober 2010
  121. 121. Geospatial stuff Samstag, 23. Oktober 2010
  122. 122. @db['people'].create_index( [["latlng", Mongo::GEO2D]] ) Samstag, 23. Oktober 2010
  123. 123. @db['people'].find( "latlng" => {"$near" => [53.593978, 10.107380]} ) Samstag, 23. Oktober 2010
  124. 124. GridFS usage Samstag, 23. Oktober 2010
  125. 125. grid = Mongo::Grid.new(@db) id = grid.put("You can put Strings in here", :filename => 'test.txt') file = grid.get(id) file.filename file.read grid.delete(id) grid.put( File.open("/Users/jankrutisch/Dropbox/Photos/IMGP8989.jpg") ) Samstag, 23. Oktober 2010
  126. 126. fs = Mongo::GridFileSystem.new(db) fs.open("test.txt", "w") do |f| f.write "You can put stuff in here" end fs.open("test.txt", "r") do |f| puts f.read end fs.delete("test.txt") Samstag, 23. Oktober 2010
  127. 127. Capped collections Samstag, 23. Oktober 2010
  128. 128. @db.create_collection('capped_numbers', :capped => true, :max => 50 ) @db.create_collection('capped_numbers', :capped => true, :size => 1024 * 64 ) Samstag, 23. Oktober 2010
  129. 129. explain Samstag, 23. Oktober 2010
  130. 130. @db['people'].find( "address.city" => /haven/ ).explain Samstag, 23. Oktober 2010
  131. 131. @db['people'].find( "address.city" => /haven/ ).explain Samstag, 23. Oktober 2010
  132. 132. { "cursor"=>"BasicCursor", "nscanned"=>1000, "nscannedObjects"=>1000, "n"=>39, "millis"=>2, "indexBounds"=>{}, "allPlans"=>[ {"cursor"=>"BasicCursor", "indexBounds"=>{}} ] } Samstag, 23. Oktober 2010
  133. 133. { "cursor"=>"BtreeCursor address.city_1 multi", "nscanned"=>1000, "nscannedObjects"=>39, "n"=>39, "millis"=>1, "indexBounds"=>{ "address.city"=>[["", {}], [/haven/, /haven/]] }, "allPlans"=>[ { "cursor"=>"BtreeCursor address.city_1 multi", "indexBounds"=>{ "address.city"=>[["", {}], [/haven/, /haven/]] } } ] } Samstag, 23. Oktober 2010
  134. 134. ODMs Samstag, 23. Oktober 2010
  135. 135. mongo_mapper Samstag, 23. Oktober 2010
  136. 136. John Nunemaker @jnunemaker Samstag, 23. Oktober 2010
  137. 137. is in production Samstag, 23. Oktober 2010
  138. 138. documentation? Samstag, 23. Oktober 2010
  139. 139. Samstag, 23. Oktober 2010
  140. 140. how to Samstag, 23. Oktober 2010
  141. 141. rails initializer Samstag, 23. Oktober 2010
  142. 142. # config/initializers/mongo_mapper.rb File.open(File.join(Rails.root, 'config/mongodb.yml'), 'r') do |f| @settings = YAML.load(f)[Rails.env] end MongoMapper.connection = Mongo::Connection.from_uri(@settings["connection"]) if @settings["connection"] MongoMapper.database = @settings["database"] Samstag, 23. Oktober 2010
  143. 143. a simple example Samstag, 23. Oktober 2010
  144. 144. MongoMapper.connection = @connection MongoMapper.database = "test" class Quote include MongoMapper::Document key :from key :text key :views, Integer timestamps! end Samstag, 23. Oktober 2010
  145. 145. finders Samstag, 23. Oktober 2010
  146. 146. Quote.where(:from => 'Yogi Berra').all Quote.where(:from => 'Yogi Berra').limit(5).sort(:from.desc).all Samstag, 23. Oktober 2010
  147. 147. embedded docs Samstag, 23. Oktober 2010
  148. 148. Samstag, 23. Oktober 2010
  149. 149. class Person include MongoMapper::Document key :name one :address key :tags, Array end class Address include MongoMapper::Document key :street key :city key :country key :zip end Samstag, 23. Oktober 2010
  150. 150. person = Person.first address = Person.first.address Samstag, 23. Oktober 2010
  151. 151. scopes Samstag, 23. Oktober 2010
  152. 152. class Person scope :tagged, lambda { |tag| where(:tags.in => [tag]) } end puts Person.tagged('cool').first.inspect Samstag, 23. Oktober 2010
  153. 153. new website coming soon Samstag, 23. Oktober 2010
  154. 154. mongoid Samstag, 23. Oktober 2010
  155. 155. Durran Jordan (of Hashrocket) Samstag, 23. Oktober 2010
  156. 156. Two major versions Samstag, 23. Oktober 2010
  157. 157. 1.x (1.9.x) targeting Rails 2.3.x Samstag, 23. Oktober 2010
  158. 158. 2.x (2.0beta) targeting Rails 3.0 Samstag, 23. Oktober 2010
  159. 159. Good documentation Samstag, 23. Oktober 2010
  160. 160. Samstag, 23. Oktober 2010
  161. 161. rails initializer Samstag, 23. Oktober 2010
  162. 162. File.open(File.join(RAILS_ROOT, 'config/mongodb.yml'), 'r') do |f| @settings = YAML.load(f)[RAILS_ENV] end Mongoid::Config.instance.from_hash(@settings) Samstag, 23. Oktober 2010
  163. 163. a simple example Samstag, 23. Oktober 2010
  164. 164. class Quote include Mongoid::Document include Mongoid::Timestamps field :from field :text field :views, :type => Integer end Samstag, 23. Oktober 2010
  165. 165. finders Samstag, 23. Oktober 2010
  166. 166. Quote.where(:from => 'Yogi Berra').all Quote.where(:from => 'Yogi Berra').limit(5).order_by(:from.desc).all Samstag, 23. Oktober 2010
  167. 167. embedded docs Samstag, 23. Oktober 2010
  168. 168. class Person include Mongoid::Document field :name embeds_one :address field :tags, :type => Array end class Address include Mongoid::Document field :street field :city field :country field :zip end Samstag, 23. Oktober 2010
  169. 169. person = Person.first address = Person.first.address Samstag, 23. Oktober 2010
  170. 170. scopes Samstag, 23. Oktober 2010
  171. 171. class Person scope :tagged, lambda { |tag| where(:tags.in => [tag]) } end puts Person.tagged('cool').first.inspect Samstag, 23. Oktober 2010
  172. 172. More features Samstag, 23. Oktober 2010
  173. 173. atomic updates Samstag, 23. Oktober 2010
  174. 174. mongoid tries to be clever Samstag, 23. Oktober 2010
  175. 175. (using the „dirty“ flags) Samstag, 23. Oktober 2010
  176. 176. (it‘s probably better to bypass the ODM sometimes) Samstag, 23. Oktober 2010
  177. 177. GridFS Samstag, 23. Oktober 2010
  178. 178. external libraries for both Samstag, 23. Oktober 2010
  179. 179. mongo_mapper > grip Samstag, 23. Oktober 2010
  180. 180. mongoid > mongoid_grid Samstag, 23. Oktober 2010
  181. 181. Other noteworthy libraries Samstag, 23. Oktober 2010
  182. 182. Other not so noteworthy libraries Samstag, 23. Oktober 2010
  183. 183. I ♥ Samstag, 23. Oktober 2010
  184. 184. thanks for listening. ‣ jan@krutisch.de ‣ http://jan.krutisch.de/ ‣ http://github.com/halfbyte/ ‣ http://twitter.com/halfbyte ‣ http://www.mindmatters.de/ ‣ http://www.mongodb.org/ ‣ http://www.mongoid.org/ ‣ http://github.com/jnunemaker/mongo_mapper ‣ http://github.com/halfbyte/mongo_ruby_examples Samstag, 23. Oktober 2010
  1. A particular slide catching your eye?

    Clipping is a handy way to collect important slides you want to go back to later.

×