Académique Documents
Professionnel Documents
Culture Documents
2...
3...
Congratulations!
1. Literally Scale
1. Literally Scale
$3,200 $4,000,000
2. Master-Slave Slave
Read
Master
Writes
Slave
Read
3. Shard
April - July 2009
Configuration
3. Shard
Server #3, lockdown.
Split the data,
migrate half to the
new shard.
Configuration
Routers
Master-Slave
master
slave
Replica Pairs
slave
Replica Pairs
master
Replica Pairs
slave
master
"Yeah, the RDBMS went down
at 2am. There wasn't any need
to wake the DBA. She can fix it
later today."
Insert this.
Insert this.
Okay
Fred
Consistency
x 1,000,000
Fred
Fail Whale
Consistency
Okay
Fred
Consistency
Okay
Fred
Bob
Consistency
One sec
Fred
Consistency
Wait a sec, Bob
Bob
Consistency
Bob
Bob
$VAR1 = {
'_id' => bless ( {
'value' => '4b55f086f8fb65f15e219195'
}, 'MongoDB::OID' ),
'name' => 'Joe',
'age' => 34
};
MongoId
$x = {"foo" => 1, "bar" => 2};
my $id = $collection->insert($x);
print "$id\n";
Result:
2fe3e4d892aa73234c910bed
MongoId
Q: How do we make a unique ID quickly that is guaranteed to
be unique across multiple servers?
A:
2fe3e4d892aa73234c910bed
|------||----||--||----|
ts mac pid inc
{
"username" => "kristina",
"level" => 9,
}
I acquire a pet
$db->users->update(
{'username' => 'kristina'},
{'$set' => {'pet' => {
'name' => 'Trot',
'species' => 'Mosquito',
'weight' => 20}}});
Kingdom of Loathing
{
"username" => "kristina",
"level" => 9,
"pet" => {
"name" => "Trot",
"species" => "Mosquito",
"weight" => 20
}
}
Kingdom of Loathing
$users->find({"pet.weight" => 20});
if ($page) {
$page->{'pageviews'}++;
$analytics->save($page);
}
else {
$analytics->insert({
"url" => "www.example.com",
"pageviews" => 1});
}
...that's 1 round trip + 1 update or insert.
Analytics - Upsert
$analytics->update(
{url => "www.example.com"},
{'$inc' => {"pageviews" => 1}},
{upsert => true});
J J J
chunks
J J J
J J J
_id : J files
Storing Files - GridFS
my $grid = $db->get_gridfs;
$grid->insert($fh,
{permissions => 644,
comment => "vacation pics"});
$file->print($fh);
$where
$c->find_one({'$where' =>
'this.y == (this.x + this.z)'});
Will work:
{"x" => 1, "y" => 4, "z" => 3}
{"x" => "hi", "y" => "hibye", "z" => "bye"}
Won’t work:
{"x" => 1, "y" => 1}
JavaScript Functions
$db->eval("function() { return 'hello'; }")
hello
$db->eval($func, ["joe"])
hello, joe!
"Stored Procedures"
$db->system->js->insert({
"_id" => "x",
"value" => 3});
$db->system->js->insert({
"_id" => "y",
"value" => 4});
$db->eval("return x+y");
JS Shell
$ ./mongo
MongoDB shell version 1.3.1-
url: test
connecting to: test
type "help" for help
> print("hello, world")
hello, world
>
JS Shell
$ ./mongo --quiet report.js > "`date`.log"
Thank You!
kristina@mongodb.org
@mongodb, @kchodorow
irc.freenode.net#mongodb
http://groups.google.com/group/mongodb-user/
www.mongodb.org