Kristina [email protected]
MongoDB: A New Genie in the LAMP (Stack)
a retrospective
SQL invented1974
now2010
SQL invented1974
now2010
SQL invented1974
now2010
1979
SQL invented1974
now2010
1979
SQL invented1974
now2010
1979
1982-1996
SQL invented1974
now2010
1995
1979
1982-1996
SQL invented1974
now2010
1995
19792010
1982-1996
until 2009...
until 2009...
SQL invented1974
now2010
1995
19792010
1982-1996
databases
contain tables
contain rows
server
databases
contain tables
contain rows
schemaserver
databases
contain tables
contain rows
joins
schemaserver
things have changed in the last 15 years
duh
SQL invented1974
now2010
1995
19792010
1982-1996
SQL invented1974
now2010
1995
19792010
1995
1982-1996
SQL invented1974
now2010
1995
19792010
19952738 websites
1994
1982-1996
SQL invented1974
now2010
1995
19792010
19952738 websites
1994
>10,000 websites
1995
1982-1996
SQL invented1974
now2010
1995
19792010
1998
19952738 websites
1994
>10,000 websites
1995
1982-1996
We should get a mainframe, old chap.
Harumph.
never leave me!
downtime becomes important
hardware ok?
hardware ok?
failover to slave
no
hardware ok?
failover to slave
fsck worked?
yes
no
hardware ok?
failover to slave
fsck worked?
yes
no
no
hardware ok?
failover to slave
fsck worked?
transaction log
yes
yes
no
no
hardware ok?
failover to slave
fsck worked?
transaction log
yes
yes
nono
no
hardware ok?
failover to slave
fsck worked?
transaction log yay!
yes
yes
yes
nono
no
hardware ok?
failover to slave
fsck worked?
transaction log yay!
yes
yes
yes
nono
no
SQL invented1974
now2010
1995
19792010
1998
19952738 websites
1994
>10,000 websites
1995
1982-1996
SQL invented1974
now2010
1995
19792010
2004
1998
19952738 websites
1994
>10,000 websites
1995
1982-1996
SQL invented1974
now2010
1995
19792010
2004
1998
1995
BigTable2004
2738 websites1994
>10,000 websites
1995
1982-1996
SQL invented1974
now2010
1995
19792010
MapReduce2005
2004
1998
1995
BigTable2004
2738 websites1994
>10,000 websites
1995
1982-1996
you left me!
eh, whatever.
prod1.example.com
prod2.example.com
prod1.example.com
prod2.example.com
prod1.example.com
prod2.example.com
prod1.example.com
prod2.example.com
prod1.example.com
prod2.example.com
prod1.example.com
prod2.example.com
prod1.example.com ?
prod2.example.com
prod2.example.com
prod1.example.com
prod2.example.com
prod1.example.com
?
prod2.example.com
prod1.example.com
prod2.example.com
prod1.example.com
primary
secondary
passive
secondary
secondary
passive
secondary
My priority is 2 My priority is
1
primary
passive
secondary
secondary
passive
secondary
I'm 3ms behind
I'm 2ms behind
secondary
passive
primary
passive
I'll still take reads.
okay
?
make sure two slaves have
this
all set
EXCEPTION
EXCEPTION
EXCEPTION
SQL invented1974
now2010
1995
19792010
MapReduce2005
2004
1998
1995
BigTable2004
2738 websites1994
>10,000 websites
1995
1982-1996
2007
Application
PHP
Linux
Apache
getting started
www.mongodb.org
$ mysqld
$ mongod
$ mysql
$ mongo
$ mongoMongoDB shell version 1.6.0connecting to: test>
$ mongoMongoDB shell version 1.6.0connecting to: test> db
$ mongoMongoDB shell version 1.6.0connecting to: test> dbtest>
$ mongoMongoDB shell version 1.6.0connecting to: test> dbtest>
NO ADMINISTRATION
$ mongoMongoDB shell version 1.6.0connecting to: test> dbtest> table = db.foo
server
databases
server
databases
contain tables
server
databases
contain tables
server
databases
contain tables
server
collections
databases
contain rows
server
contain tables collections
databases
contain rows
server
contain tables collections
databases
contain rows
server
contain tables collections documents
databases
contain rows
server
contain tables collections documents
schema
databases
contain rows
server
contain tables collections documents
schema
joins
databases
contain collections
contain documents
server
$ mongoMongoDB shell version 1.5.5url: testconnecting to: testtype "help" for help> dbtest> collection = db.foo
$ mongoMongoDB shell version 1.5.5url: testconnecting to: testtype "help" for help> dbtest> collection = db.foo
NO ADMINISTRATION
{ "name" : "kristina", "contact info" : { "twitter" : "@kchodorow", "email" : "[email protected]" }, "friends" : 400232, "pic" : BinData(...) "member since" : new Date()}
> doc = { "name" : "kristina", "contact info" : { "twitter" : "@kchodorow", "email" : "[email protected]" }, "friends" : 400232, "pic" : BinData(...) "member since" : new Date()}
> db.foo.insert(doc)
> db.foo.findOne({"name" : "kristina"});
> db.foo.findOne({"name" : "kristina"})
> db.foo.findOne({... "contact.twitter" : "@kchodorow"})
> db.foo.findOne({"name" : "kristina"})
> db.foo.findOne({... "contact.twitter" : "@kchodorow"})
> db.foo.find({... "member since" : {... "$gt" : yesterday,... "$lt" : today... }})
> db.foo.findOne({"name" : "kristina"})
> db.foo.findOne({... "contact.twitter" : "@kchodorow"})
> db.foo.find({... "member since" : {... "$gt" : yesterday,... "$lt" : today... }}).sort({friends : 1}).limit(10).... skip(100)
db.people.update( {name : "kristina"},
db.people.update( {name : "kristina"}, {$set :
db.people.update( {name : "kristina"}, {$set : {"contact.website" : "snailinaturtleneck.com"}});
> db.pageviews.update( {url : "example.com"}, {$inc : {pageviews : 1}}, true)
some features
I suddenly have a deep love for stored
procedures
I suddenly have a deep love for stored
procedures
now wi
th store
d
procedu
res!
> db.system.js.insert({
"_id" : "x",
"value" : 3});
> db.system.js.insert({
"_id" : "y",
"value" : 4});
> db.eval("return x+y")
> db.system.js.insert({_id : "log",
... value : function(msg, level) {
... var date = "[" + new Date() + "] ";
... var lvl = level ? level+" " : "";
... print(date + lvl + msg);
... }})
> db.eval("log('all your base are
belong to us', 'FATAL');");
> db.eval("log('all your base are
belong to us', 'FATAL');");
[Fri May 19 18:34:57] FATAL all your
base are belong to us
capped collections
indexes
geospatial indexes
MapReduce
scaling
(rdbms)
silly putty
U - ZK - OA - E F - J P - T
U - ZK - OA - E F - J P - T
I want Mark through Sarah.
U - ZK - OA - E F - J P - T
U - ZK - OA - E F - J P - T
U - ZK - OA - E F - J P - T
Insert Linus
U - ZK - OA - E F - J P - T
Insert Linus
U - ZK - OA - E F - J P - T
$ mongoMongoDB shell version 1.6.0connecting to: test>
$ mongoMongoDB shell version 1.6.0connecting to: test> db.foo.insert({x:1})
thank you!
@kchodorow
http://www.snailinaturtleneck.com