Steve Klabnik
Pittsburgh Ruby Brigade
        October 7, 2010
“The best features of
Document Databases,
  Key-Value Stores,
  and RDBMSes.”
Document Database
JSON
BSON
http://hackety-hack.com/
http://github.com/hacketyhack/hackety-hack.com
post = {
  "_id" : ObjectId("4c67892ba8d8770eb8000003"),
  "title" : "Welcome to the Hackety Site!",
  "body" : "This is a...
post = {
  "_id" : ObjectId("4c67892ba8d8770eb8000003"),
  "title" : "Welcome to the Hackety Site!",
  "body" : "This is a...
post = {
  "_id" : ObjectId("4c67892ba8d8770eb8000003"),
  "title" : "Welcome to the Hackety Site!",
  "body" : "This is a...
post = {
  "_id" : ObjectId("4c67892ba8d8770eb8000003"),
  "title" : "Welcome to the Hackety Site!",
  "body" : "This is a...
Look, Ma! No Schema!
post = {
  "_id" : ObjectId("4c67892ba8d8770eb8000004"),
  "title" : "Here’s a cool update!",
  "body" : "This is an expla...
$ mongo
MongoDB shell version: 1.6.3
connecting to: test
> use hackety-development;
switched to db hackety-development
> s...
> db.users.find({“username”:”steve”})
> db.posts.find({“tags”:{$in:[“ruby”, “rails”]}})
JavaScript
> f = function(x) { return x + 1; }
function (x) {
   return x + 1;
}
> f(2);
3
JSON == {}
JSON == {}
(1.9.x)
$ rvm use 1.9.2

info: Using ruby 1.9.2 p0
$ irb
ruby-1.9.2-p0 > {lol: "wut"}
 => {:lol=>"wut"}
ruby-1.9.2-p0 >
“Why I think Mongo is to
                     Databases what Rails was
                         to Frameworks”
http://rail...
Map / Reduce
Map / Reduce
functional programming concepts
Map: Enumerable#map
map :: (a -> b) -> [a] -> [b]
    (transforms one list into another list
               via a function)
Reduce: Enumerable#inject
foldl :: (a -> b -> a) -> a -> [b] -> a
           (takes a function with two arguments,
         a starting point, and a ...
functional programming concepts
distributed computing
$ ./mongo
> db.things.insert(   { _id : 1, tags : ['dog', 'cat'] } );
> db.things.insert(   { _id : 2, tags : ['cat'] } );...
class Post
  include MongoMapper::Document

  key :title, String
  key :body, String

  key :slug, String

  many :comment...
“Software Engineering is the art of
            choosing
  the correct set of tradeoffs”-Me
# 1000
 mongokit django_mongokit.mongodb
 Creating 1000 talks took 0.957674026489
seconds
 Editing 1000 talks took 1.60552...
Rich Documents == Less Querying
ACID
(Atomicity, Consistency, Isolation, Durability)
Durability, Schmerability
         (single server)
32 bit?
Use the right tool
Thanks
           @steveklabnik
       http://steveklabnik.com/
http://www.slideshare.net/SteveKlabnik
MongoDB
MongoDB
MongoDB
MongoDB
MongoDB
MongoDB
MongoDB
MongoDB
MongoDB
MongoDB
MongoDB
MongoDB
MongoDB
Upcoming SlideShare
Loading in …5
×

MongoDB

1,191 views

Published on

A little presentation about the basics of MongoDB, for the PIttsburgh Ruby Brigade.

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

  • Be the first to like this

No Downloads
Views
Total views
1,191
On SlideShare
0
From Embeds
0
Number of Embeds
38
Actions
Shares
0
Downloads
19
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide






















































  • MongoDB

    1. 1. Steve Klabnik Pittsburgh Ruby Brigade October 7, 2010
    2. 2. “The best features of Document Databases, Key-Value Stores, and RDBMSes.”
    3. 3. Document Database
    4. 4. JSON
    5. 5. BSON
    6. 6. http://hackety-hack.com/ http://github.com/hacketyhack/hackety-hack.com
    7. 7. post = { "_id" : ObjectId("4c67892ba8d8770eb8000003"), "title" : "Welcome to the Hackety Site!", "body" : "This is an intial post, so that you can see how everything looks. ", "updated_at" : "Sun Aug 15 2010 02:28:59 GMT-0400 (EDT)" "created_at" : "Sun Aug 15 2010 02:28:59 GMT-0400 (EDT)", "comments" : [ { "body" : "This post is awesome! I've never seen such insightful writing!!", "author" : "somebody", "_id" : ObjectId("4c67892ba8d8770eb8000004"), "author_email" : "somebody@example.com" } ], }
    8. 8. post = { "_id" : ObjectId("4c67892ba8d8770eb8000003"), "title" : "Welcome to the Hackety Site!", "body" : "This is an intial post, so that you can see how everything looks. ", "updated_at" : "Sun Aug 15 2010 02:28:59 GMT-0400 (EDT)" "created_at" : "Sun Aug 15 2010 02:28:59 GMT-0400 (EDT)", "comments" : [ { "body" : "This post is awesome! I've never seen such insightful writing!!", "author" : "somebody", "_id" : ObjectId("4c67892ba8d8770eb8000004"), "author_email" : "somebody@example.com" } ], }
    9. 9. post = { "_id" : ObjectId("4c67892ba8d8770eb8000003"), "title" : "Welcome to the Hackety Site!", "body" : "This is an intial post, so that you can see how everything looks. ", "updated_at" : "Sun Aug 15 2010 02:28:59 GMT-0400 (EDT)" "created_at" : "Sun Aug 15 2010 02:28:59 GMT-0400 (EDT)", "comments" : [ { "body" : "This post is awesome! I've never seen such insightful writing!!", "author" : "somebody", "_id" : ObjectId("4c67892ba8d8770eb8000004"), "author_email" : "somebody@example.com" } ], }
    10. 10. post = { "_id" : ObjectId("4c67892ba8d8770eb8000003"), "title" : "Welcome to the Hackety Site!", "body" : "This is an intial post, so that you can see how everything looks. ", "updated_at" : "Sun Aug 15 2010 02:28:59 GMT-0400 (EDT)" "created_at" : "Sun Aug 15 2010 02:28:59 GMT-0400 (EDT)", "comments" : [ { "body" : "This post is awesome! I've never seen such insightful writing!!", "author" : "somebody", "_id" : ObjectId("4c67892ba8d8770eb8000004"), "author_email" : "somebody@example.com" } ], }
    11. 11. Look, Ma! No Schema!
    12. 12. post = { "_id" : ObjectId("4c67892ba8d8770eb8000004"), "title" : "Here’s a cool update!", "body" : "This is an explanation of all the new features!", "updated_at" : "Sun Aug 15 2010 02:29:60 GMT-0400 (EDT)" "created_at" : "Sun Aug 15 2010 02:29:60 GMT-0400 (EDT)", }
    13. 13. $ mongo MongoDB shell version: 1.6.3 connecting to: test > use hackety-development; switched to db hackety-development > show collections; discussions hackers messages posts programs system.indexes users > db.posts.find(); { "_id" : ObjectId("...
    14. 14. > db.users.find({“username”:”steve”})
    15. 15. > db.posts.find({“tags”:{$in:[“ruby”, “rails”]}})
    16. 16. JavaScript
    17. 17. > f = function(x) { return x + 1; } function (x) { return x + 1; } > f(2); 3
    18. 18. JSON == {}
    19. 19. JSON == {}
    20. 20. (1.9.x)
    21. 21. $ rvm use 1.9.2 info: Using ruby 1.9.2 p0 $ irb ruby-1.9.2-p0 > {lol: "wut"} => {:lol=>"wut"} ruby-1.9.2-p0 >
    22. 22. “Why I think Mongo is to Databases what Rails was to Frameworks” http://railstips.org/blog/archives/2009/12/18/why-i-think-mongo-is-to-databases-what-rails-was-to-frameworks/
    23. 23. Map / Reduce
    24. 24. Map / Reduce
    25. 25. functional programming concepts
    26. 26. Map: Enumerable#map
    27. 27. map :: (a -> b) -> [a] -> [b] (transforms one list into another list via a function)
    28. 28. Reduce: Enumerable#inject
    29. 29. foldl :: (a -> b -> a) -> a -> [b] -> a (takes a function with two arguments, a starting point, and a list, and repeatedly calls that function until only one value is left)
    30. 30. functional programming concepts
    31. 31. distributed computing
    32. 32. $ ./mongo > db.things.insert( { _id : 1, tags : ['dog', 'cat'] } ); > db.things.insert( { _id : 2, tags : ['cat'] } ); > db.things.insert( { _id : 3, tags : ['mouse', 'cat', 'dog'] } ); > db.things.insert( { _id : 4, tags : [] } ); > // map function > m = function(){ ... this.tags.forEach( ... function(z){ ... emit( z , { count : 1 } ); ... } ... ); ...}; > // reduce function > r = function( key , values ){ ... var total = 0; ... for ( var i=0; i<values.length; i++ ) ... total += values[i].count; ... return { count : total }; ...}; > res = db.things.mapReduce(m,r); > res {"timeMillis.emit" : 9 , "result" : "mr.things. 1254430454.3" , "numObjects" : 4 , "timeMillis" : 9 , "errmsg" : "" , "ok" : 0} > db[res.result].find() {"_id" : "cat" , "value" : {"count" : 3}} {"_id" : "dog" , "value" : {"count" : 2}} {"_id" : "mouse" , "value" : {"count" : 1}}
    33. 33. class Post   include MongoMapper::Document   key :title, String   key :body, String   key :slug, String   many :comments   timestamps! end
    34. 34. “Software Engineering is the art of choosing the correct set of tradeoffs”-Me
    35. 35. # 1000 mongokit django_mongokit.mongodb Creating 1000 talks took 0.957674026489 seconds Editing 1000 talks took 1.60552191734 seconds Deleting 1000 talks took 1.28869891167 seconds IN TOTAL 3.8518948555 seconds sql django.db.backends.postgresql_psycopg2 Creating 1000 talks took 8.57405209541 seconds Editing 1000 talks took 14.8357069492 seconds Deleting 1000 talks took 11.9729249477 seconds http://www.peterbe.com/plog/speed-test-between-django_mongokit-and-postgresql_psycopg2
    36. 36. Rich Documents == Less Querying
    37. 37. ACID (Atomicity, Consistency, Isolation, Durability)
    38. 38. Durability, Schmerability (single server)
    39. 39. 32 bit?
    40. 40. Use the right tool
    41. 41. Thanks @steveklabnik http://steveklabnik.com/ http://www.slideshare.net/SteveKlabnik

    ×