3. • 15+ years building the
internet
• Father, husband,
skateboarder
• Chief Solutions Architect @
10gen
• Author of upcoming O’Reilly
publication “PHP and
MongoDB”
19. Signs something
needed
•doubleclick - 400,000 ads/second
•caching is de rigueur
•complex ORM frameworks
•computer architecture increasing in
complexity
•cloud computing
20. Requirements
We need enough functionality to handle
broad set of use cases
•strong consistency / atomicity
•secondary indexes
•ad hoc queries
21. Trim unneeded
features
Leave out a few things so we can scale
•no choice but to leave out relational
•distributed transactions are hard to
scale
22. Needed a scalable
data model
Considered....
•key/value
•columnar / tabular
•document oriented (JSON inspired)
23. MongoDB philosphy
• Keep functionality when we can (key/
value stores are great, but we need more)
• Non-relational (no joins) makes scaling
horizontally practical
• Document data models are good
• Database technology should run
anywhere VMs, cloud or straight metal
24. MongoDB is:
Application Document
Oriented
{ author: “steve”,
High date: new Date(),
text: “About MongoDB...”,
Performance tags: [“tech”, “database”]}
Fully
Consistent
Horizontally Scalable
30. CMS / Blog
Needs:
• Business needed modern data store for rapid development and
scale
Solution:
• Use PHP & MongoDB
Results:
• Real time statistics
• All data, images, etc stored together, easy access, easy
deployment, easy high availability
• No need for complex migrations
• Enabled very rapid development and growth
31. Photo Meta-Data
Problem:
• Business needed more flexibility than Oracle could deliver
Solution:
• Use MongoDB instead of Oracle
Results:
• Developed application in one sprint cycle
• 500% cost reduction compared to Oracle
• 900% performance improvement compared to Oracle
32. Customer Analytics
Problem:
• Deal with massive data volume across all customer sites
Solution:
• Use MongoDB to replace Google Analytics / Omniture options
Results:
• Less than one week to build prototype and prove business case
• Rapid deployment of new features
33. Online Dictionary
Problem:
• MySQL could not scale to handle their 5B+ documents
Solution:
• Switched from MySQL to MongoDB
Results:
• Massive simplification of code base
• Eliminated need for external caching system
• 20x performance improvement over MySQL
34. E-commerce
Problem:
• Multi-vertical E-commerce impossible to model (efficiently) in
RDBMS
Solution:
• Switched from MySQL to MongoDB
Results:
• Massive simplification of code base
• Rapidly build, halving time to market (and cost)
• Eliminated need for external caching system
• 50x+ improvement over MySQL
47. Connecting to the DB
$connection = new Mongo();
$db = $connection->selectDB('blog');
$posts = $db->post;
If the DB or collection doesn’t exist,
mongoDB will create it on connect.
48. Documents
Blog Post Document
$p1 = array("author" => "roger",
"date" => new MongoDate(),
"text" => "about mongoDB...",
"tags" => array('tech', 'databases')
);
$posts->save($p1);
49. Querying
print_r($posts->findOne());
> db.posts.findOne()
Array(
[_id] => MongoId Object(
> { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
[$id] => 4e9796764a18173a17000000
author : "roger",
)
date : "Sat Jul 24 2010 19:47:11",
[author] => roger
text : "About MongoDB...",
[date] => MongoDate Object(
tags : [ "tech", "databases" ] }
[sec] => 1318557302
[usec] => 581000
)
[text] => about mongoDB...
[tags] => Array(
Note: _id is unique, but can be anything
[0] => tech
[1] => databases
you’d like
)
)
50. Querying
print_r($posts->findOne());
> db.posts.findOne()
Array(
[_id] => MongoId Object(
> { _id : ObjectId("4c4ba5c0672c685e5e8aabf3"),
[$id] => 4e9796764a18173a17000000
author : "roger",
)
date : "Sat Jul 24 2010 19:47:11",
[author] => roger
text : "About MongoDB...",
[date] => MongoDate Object(
tags : [ "tech", "databases" ] }
[sec] => 1318557302
[usec] => 581000
)
[text] => about mongoDB...
[tags] => Array(
Note: _id is unique, but can be anything
[0] => tech
[1] => databases
you’d like
)
)
51. Inserting Objects
class PostObj {
public $comments = array();
public function __construct($author, $title, $content)
{
$this->author = $author;
$this->title = $title;
$this->content = $content;
}
}
$posts->insert(new PostObj("Steve",
"My first blog post",
"Hello, World!"));
70. A better network FS
• GridFS files are seamlessly sharded & replicated.
• No OS constraints...
• No file size limits
• No naming constraints
• No folder limits
• Standard across different OSs
• MongoDB automatically generate the MD5 hash
of the file
71. Storing Files
$grid = $db->getGridFS();
// The file's location in the File System
$path = "/tmp/";
$filename = "movie.mp4";
// Note metadata field & filename field
$storedfile = $grid->storeFile($path . $filename,
array("metadata" => array("filename" => $filename),
"filename" => $filename));
// Return newly stored file's Document ID
echo $storedfile;
76. Doctrine MongoDB ODM
• Provides full validation
• Seamless integration with Doctrine ORM
• Useful for hybrid solutions
• Follows same persistence model as Doctrine
• Uses a Document Manager & annotations
• Supports embedded and referenced objects
• Can use mongo’s query interface
• Supports in place updates
https://github.com/doctrine/mongodb-odm
77. Mandango
•Very light and fast
•Event support
•Supports embedded and referenced
objects
•uses the mongo query syntax
•Lacking validation, but events can be
utilized to validate
https://github.com/mandango/mandango
78. Active Mongo
•Uses ActiveRecord (active document)
interface
•Supports full validation
•Supports in place updating
•Uses native query interface
•Supports referenced documents
https://github.com/crodas/ActiveMongo
79. Morph
•Follows the Active Record model
•Has own query object (Morph_Query)
•Doesn’t provide validation
•Doesn’t support embedded or referenced
objects.
https://github.com/a-musing-moose/morph
80. Mongo Queue
An extensible job/message queueing system that
uses mongodb as the persistent storage engine.
• Fully Configurable
• Distributed
• Atomic Locking
• Priority Support
• Worker Timeout Support
• Stable
https://github.com/skiz/mongo_queue
81. http://spf13.com
http://github.com/spf13
@spf13
Questions?
download at mongodb.org
PS: We’re hiring!! Contact us at jobs@10gen.com
Notas del editor
\n
\n
\n
\n
\n
\n
\n
\n
\n
\n
Remember in 1995 there were around 10,000 websites. Mosiac, Lynx, Mozilla (pre netscape) and IE 2.0 were the only web browsers. \nApache (Dec ’95), Java (’96), PHP (June ’95), and .net didn’t exist yet. Linux just barely (1.0 in ’94)\n
Remember in 1995 there were around 10,000 websites. Mosiac, Lynx, Mozilla (pre netscape) and IE 2.0 were the only web browsers. \nApache (Dec ’95), Java (’96), PHP (June ’95), and .net didn’t exist yet. Linux just barely (1.0 in ’94)\n
Remember in 1995 there were around 10,000 websites. Mosiac, Lynx, Mozilla (pre netscape) and IE 2.0 were the only web browsers. \nApache (Dec ’95), Java (’96), PHP (June ’95), and .net didn’t exist yet. Linux just barely (1.0 in ’94)\n
\n
\n
\n
\n
\n
\n
\n
\n
By reducing transactional semantics the db provides, one can still solve an interesting set of problems where performance is very important, and horizontal scaling then becomes easier.\n\n