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
•  ...
Schema-free

• Loosening constraints - added flexibility
• Dynamically typed languages
• Migrations
BigTable

• Single master node
• Row / Column hybrid
• Versioned
BigTable

• Open-source clones:
 • HBase
 • Hypertable
Dynamo
• Simple Key/Value store
• No master node
 • Write to any (many) nodes
 • Read from one or more nodes (balance
    ...
Dynamo

• Open-source clones
 • Project Voldemort
 • Cassandra - data model more like
    BigTable
 • Dynomite
memcached

• Used as a caching layer
• Essentially a key/value store
• RAM only - fast
• Does away with ACID
Redis

• Like memcached
• Different
 • Values can be strings, lists, sets
 • Non-volatile
Tokyo Cabinet + Tyrant

• Key/value store with focus on speed
• Some more advanced queries
 • Sorting, range or prefix matc...
• A lot in common with MongoDB:
 • Document-oriented
 • Schema-free
 • JSON-style documents
• Differences
 • MVCC based
 • Replication as path to scalability
 • Query through predefined views
 • ACID
 • REST
• Focus on performance
• Rich dynamic queries
• Secondary indexes
• Replication / failover
• Auto-sharding
• Many platform...
Good at

• The web
• Caching
• High volume / low value
• Scalability
Less good at

• Highly transactional
• Ad-hoc business intelligence
• Problems that require SQL
Mongo PHP Driver

• PHP extension
• Available on PECL
          pecl install mongo
Document

• Unit of storage (think row)
• Just an Array
• Can store dates, integers, floating point,
  strings, etc.
Collection

• Schema-free equivalent of a table
• Logical groups of documents
• Indexes are per-collection
Blog back-end
Post

array(‘author’ => ‘mike’,
 ‘date’ => new MongoDate(),
 ‘text’ => ‘my blog post...’,
 ‘tags’ => array(‘mongodb’, ‘php...
New post

$doc = array(‘author’ => ‘mike’,
 ‘date’ => new MongoDate(),
 ‘text’ => ‘my blog post...’,
 ‘tags’ => array(‘mon...
Last 10 posts
$cursor = $posts->find()->
          sort(array(‘date’=>-1))->
          limit(10);

foreach($cursor as $pos...
Posts by author


$posts->find(array(‘author’=>‘mike’))
Posts ending with ‘PHP’


$posts->find(array(‘text’=>new MongoRegex(‘/PHP$/’)))
Posts with a tag
$posts->find(array(‘tag’=>‘mongodb’))




           ... and fast
$posts->ensureIndex(array(‘tag’=>1))
Counting posts


$posts->count()

$posts->find(array(‘author’=>‘mike’))->count()
Migration: adding titles


• Easy - just start adding them to documents
Advanced queries

    • $gt, $lt, $gte, $lte, $ne, $all, $in, $nin
    • $where clause
“this.author == ‘mike’ || this.comm...
Other cool stuff
• Capped collections
• Unique indexes
• Mongo shell
• GridFS
• morph - http://code.google.com/p/
  mongod...
• Download MongoDB
  http://www.mongodb.org

• Install the PHP Driver
• Try it out!
• http://www.mongodb.org
• irc.freenode.net#mongodb
• mongodb-user on google groups
• @mongodb, @mdirolf
• mike@10gen.com
...
MongoDB London PHP
Upcoming SlideShare
Loading in...5
×

MongoDB London PHP

10,888

Published on

MongoDB talk from the July '09 London PHP meetup.

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

No Downloads
Views
Total Views
10,888
On Slideshare
0
From Embeds
0
Number of Embeds
0
Actions
Shares
0
Downloads
233
Comments
0
Likes
20
Embeds 0
No embeds

No notes for slide

Transcript of "MongoDB London PHP"

  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. Schema-free • Loosening constraints - added flexibility • Dynamically typed languages • Migrations
  6. 6. BigTable • Single master node • Row / Column hybrid • Versioned
  7. 7. BigTable • Open-source clones: • HBase • Hypertable
  8. 8. Dynamo • Simple Key/Value store • No master node • Write to any (many) nodes • Read from one or more nodes (balance speed vs. consistency) • Read repair
  9. 9. Dynamo • Open-source clones • Project Voldemort • Cassandra - data model more like BigTable • Dynomite
  10. 10. memcached • Used as a caching layer • Essentially a key/value store • RAM only - fast • Does away with ACID
  11. 11. Redis • Like memcached • Different • Values can be strings, lists, sets • Non-volatile
  12. 12. Tokyo Cabinet + Tyrant • Key/value store with focus on speed • Some more advanced queries • Sorting, range or prefix matching • Multiple storage engines • Hash, B-Tree, Fixed length and Table
  13. 13. • A lot in common with MongoDB: • Document-oriented • Schema-free • JSON-style documents
  14. 14. • Differences • MVCC based • Replication as path to scalability • Query through predefined views • ACID • REST
  15. 15. • Focus on performance • Rich dynamic queries • Secondary indexes • Replication / failover • Auto-sharding • Many platforms / languages supported
  16. 16. Good at • The web • Caching • High volume / low value • Scalability
  17. 17. Less good at • Highly transactional • Ad-hoc business intelligence • Problems that require SQL
  18. 18. Mongo PHP Driver • PHP extension • Available on PECL pecl install mongo
  19. 19. Document • Unit of storage (think row) • Just an Array • Can store dates, integers, floating point, strings, etc.
  20. 20. Collection • Schema-free equivalent of a table • Logical groups of documents • Indexes are per-collection
  21. 21. Blog back-end
  22. 22. Post array(‘author’ => ‘mike’, ‘date’ => new MongoDate(), ‘text’ => ‘my blog post...’, ‘tags’ => array(‘mongodb’, ‘php’))
  23. 23. New post $doc = array(‘author’ => ‘mike’, ‘date’ => new MongoDate(), ‘text’ => ‘my blog post...’, ‘tags’ => array(‘mongodb’, ‘php’)); $collection->save($doc);
  24. 24. Last 10 posts $cursor = $posts->find()-> sort(array(‘date’=>-1))-> limit(10); foreach($cursor as $post) { echo $post[‘text’]; }
  25. 25. Posts by author $posts->find(array(‘author’=>‘mike’))
  26. 26. Posts ending with ‘PHP’ $posts->find(array(‘text’=>new MongoRegex(‘/PHP$/’)))
  27. 27. Posts with a tag $posts->find(array(‘tag’=>‘mongodb’)) ... and fast $posts->ensureIndex(array(‘tag’=>1))
  28. 28. Counting posts $posts->count() $posts->find(array(‘author’=>‘mike’))->count()
  29. 29. Migration: adding titles • Easy - just start adding them to documents
  30. 30. Advanced queries • $gt, $lt, $gte, $lte, $ne, $all, $in, $nin • $where clause “this.author == ‘mike’ || this.comments.length > 5” • group
  31. 31. Other cool stuff • Capped collections • Unique indexes • Mongo shell • GridFS • morph - http://code.google.com/p/ mongodb-morph/
  32. 32. • Download MongoDB http://www.mongodb.org • Install the PHP Driver • Try it out!
  33. 33. • http://www.mongodb.org • irc.freenode.net#mongodb • mongodb-user on google groups • @mongodb, @mdirolf • mike@10gen.com • http://www.slideshare.net/mdirolf
  1. A particular slide catching your eye?

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

×