Training
           http://www.mongodb.org/
Hi,	
  I’m	
  Mike.
• memcached
scalability	
  &	
  performance



                                      • key/value



                      ...
Key-­‐Value


MongoDB
              Relational
Goals for Today
“ODM”s



      Ruby	
  driver



The	
  “mongo”	
  JS	
  shell
Installing	
  MongoDB
documents
collections
dynamic	
  queries
secondary	
  indexes	
  	
  
explain
BSON
                     {“hello”:	
  “bson”}



x15	
  x00	
  x00	
  x00	
  x02	
  	
  	
  	
  h	
  	
  	
  	
  e
	
  	
...
bsonspec.org
Messages


• TCP/IP Wire Protocol
• Separate messages for
  insert, update, query, get_more, delete, etc.




      http:/...
Anatomy of an insert
    use	
  foo;
    db.test.insert({“hello”:	
  “bson”});



message length      request id          ...
_id is the primary key
all about object ids
MongoDB standard
Timestamp
12-byte BSON type
If you still use a string, careful:
what’s in an oid?
what’s in an oid?
4b6857a0
timestamp
what’s in an oid?
4b6857a07613c3
timestamp
machine id
what’s in an oid?
4b6857a07613c36709
timestamp
machine id
process id
what’s in an oid?
4b6857a07613c367094426b2
timestamp
machine id
process id
counter
Simulating a flexible schema
Simulating a flexible schema




What’s the   join like?
Simulating a flexible schema




What’s the   join like?
Can we   reason    about it?
{:sku => ‘637636’,
 :name => ‘Linen tailored pant’,
 :about => [{:title => ‘fabric & care’,
              :content => [‘Dr...
simplify tiny relations
simplify tiny relations
simplify tiny relations
simplify tiny relations
many-to-many
many-to-many
many-to-many
many-to-many
many-to-many
Commands
             db.foo.drop();

                 =
  db.foo.runCommand({drop:	
  "foo"});
                 =
   db.$...
Query optimizer
     find({x:	
  10,	
  y:	
  “foo”})


         scan
                            terminate
   index on x
...
Replication
                            master   slave

        master
                            master   slave


slave ...
Replication


• oplog - capped collection
• idempotent ($inc -> $set)
Auto-sharding
                   Shards
          mongod   mongod    mongod
                                            .....
Geohashing
                  (20, 10)
     (0001	
  0100,	
  0000	
  1010)
        0000	
  0010	
  0110	
  0100
(21, 9) 00...
FrozenRails Training
Upcoming SlideShare
Loading in...5
×

FrozenRails Training

2,741

Published on

1 Comment
7 Likes
Statistics
Notes
No Downloads
Views
Total Views
2,741
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
0
Comments
1
Likes
7
Embeds 0
No embeds

No notes for slide

FrozenRails Training

  1. 1. Training http://www.mongodb.org/
  2. 2. Hi,  I’m  Mike.
  3. 3. • memcached scalability  &  performance • key/value • RDBMS depth  of  functionality
  4. 4. Key-­‐Value MongoDB Relational
  5. 5. Goals for Today
  6. 6. “ODM”s Ruby  driver The  “mongo”  JS  shell
  7. 7. Installing  MongoDB
  8. 8. documents collections dynamic  queries secondary  indexes     explain
  9. 9. BSON {“hello”:  “bson”} x15  x00  x00  x00  x02        h        e      l        l        o  x00  x05  x00  x00 x00        b        s        o        n  x00  x00 http://bsonspec.org
  10. 10. bsonspec.org
  11. 11. Messages • TCP/IP Wire Protocol • Separate messages for insert, update, query, get_more, delete, etc. http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol
  12. 12. Anatomy of an insert use  foo; db.test.insert({“hello”:  “bson”}); message length request id response id op code (insert) x67x00x00x00 xXXxXXxXXxXX x00x00x00x00 xd2x07x00x00 reserved collection name document(s) x00x00x00x00 f  o  o  .  t  e  s  t  x00 BSON({“hello”:  “bson”}) http://www.mongodb.org/display/DOCS/Mongo+Wire+Protocol
  13. 13. _id is the primary key
  14. 14. all about object ids MongoDB standard Timestamp 12-byte BSON type If you still use a string, careful:
  15. 15. what’s in an oid?
  16. 16. what’s in an oid? 4b6857a0 timestamp
  17. 17. what’s in an oid? 4b6857a07613c3 timestamp machine id
  18. 18. what’s in an oid? 4b6857a07613c36709 timestamp machine id process id
  19. 19. what’s in an oid? 4b6857a07613c367094426b2 timestamp machine id process id counter
  20. 20. Simulating a flexible schema
  21. 21. Simulating a flexible schema What’s the join like?
  22. 22. Simulating a flexible schema What’s the join like? Can we reason about it?
  23. 23. {:sku => ‘637636’, :name => ‘Linen tailored pant’, :about => [{:title => ‘fabric & care’, :content => [‘Dry clean’, ‘Imported’]}, {:title => ‘overview’, :content => [‘Tailored fit’, ‘Yarn dyed’]} ] } *
  24. 24. simplify tiny relations
  25. 25. simplify tiny relations
  26. 26. simplify tiny relations
  27. 27. simplify tiny relations
  28. 28. many-to-many
  29. 29. many-to-many
  30. 30. many-to-many
  31. 31. many-to-many
  32. 32. many-to-many
  33. 33. Commands db.foo.drop(); = db.foo.runCommand({drop:  "foo"}); = db.$cmd.findOne({drop:  "foo"}); = db.$cmd.find({drop:  "foo"}).limit(-­‐1);
  34. 34. Query optimizer find({x:  10,  y:  “foo”}) scan terminate index on x index on y remember
  35. 35. Replication master slave master master slave slave slave slave master master slave master
  36. 36. Replication • oplog - capped collection • idempotent ($inc -> $set)
  37. 37. Auto-sharding Shards mongod mongod mongod ... Config mongod mongod mongod Servers mongod mongod mongod mongos mongos ... client
  38. 38. Geohashing (20, 10) (0001  0100,  0000  1010) 0000  0010  0110  0100 (21, 9) 0000  0010  0110  0011 Problem: bit-flips (127 vs 128)

×