mongodb san francisco drupalcon 2010
TRANSCRIPT
Karoly NegyesiDeveloper team leadNowPublic.com / Examiner.com
History
Ingres early 1970s
Oracle 1979
MySQL 1982
PostGRES 1986
Moore's law
Doubling every 18 months
Applies to:Processing speed
Memory capacity
Hard disk capacity
We need drastically different design
http://varnish-cache.org/wiki/ArchitectNotes
And now some Bayou slides...www.cs.berkeley.edu/~istoica/classes/cs268/06/notes/20-BFTx2.pdf
SQL
Rigid schema
Normal forms
Transactions
Rich feature set http://dev.mysql.com/doc/refman/5.0/en/string-functions.html
Databases are operating systems that you don't have to write sound drivers for. - Brian Akerhttp://twitter.com/timoreilly/status/12247022198
Reality
The world is not rigid
Denormalization
Too much overhead for transactions
Most of features are rarely needed
Even worse
The iPhone
NoSQL
Very new
Key-value stores
Document stores
Performant
Scalable
Not too many features
MongoDB
Databases
Collections
Documents
Strictly but dynamically typed
Arrays and objects
In place updates
Foreign key support
Native PHP driver
Simple example
db.things.save({ x : 3 })
db.things.save({ y : 4 })
db.things.find(){ "_id" : ObjectId("4b10d1997bd1e19a46fc8862"), "x" : 3 }{ "_id" : ObjectId("4b10d1aa7bd1e19a46fc8863"), "y" : 4 }
ObjectID
By default generated
Can be anything as long it's unique
Update
db.things.save({a:1,b:2,c:3})
o=db.things.findOne({b:2})
o.c=4
db.things.update({b:2}, o)
db.things.find(){ "a" : 1, "b" : 2, "c" : 4 }
Modifier operators
db.things.update({ b : 2} , { $set : { c : 4 }})
db.things.find(){"a" : 1, "b" : 2, "c" : 4 }
db.things.update({ b : 2} , { $inc : { c : 100 }})
db.things.find()
{"a" : 1, "b" : 2, "c" : 104 }
Arrays
db.things.save({a:[1,2,3]})
db.things.save({a:[5,6,7]})
db.things.find({a:2})
{ "a" : [ 1, 2, 3 ] }
Array modification
db.things.insert({n:1,a:[1,2,3]})
db.things.update({n:1},{$push:{a:4}})
db.things.find(){ "n" : 1, "a" : [ 1, 2, 3, 4 ] }
Objects
db.things.save({db:{name:'mongodb', interesting:true }})
db.things.save({db:{name:'mysql', interesting:false }})
db.things.find({'db.interesting':true}){"db" : { "name" : "mongodb", "interesting" : true } }
Indexes
Anything can be indexed
Objects
Arrays
New design
Not much design is needed...
Search for ids and then load the rest
What are great fits
StatisticsMany writes
Loss is not that big a deal
Fluid dataProducts in a web store
User profiles
Not so good fit
Very complex queries
Transaction needs
Drupal and Mongo
Cache
Field_storage. Oh yes!
Session
Watchdog
Block
Queue
Crazy...
DBTNG driver