Mongodbinaction 100122230824-phpapp01

863 views

Published on

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

  • Be the first to like this

No Downloads
Views
Total views
863
On SlideShare
0
From Embeds
0
Number of Embeds
77
Actions
Shares
0
Downloads
13
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Mongodbinaction 100122230824-phpapp01

  1. 1. MongoDB In Action<br />超群.com<br />@fuchaoqun<br />http://www.fuchaoqun.com<br />
  2. 2. I will talk ….<br /><ul><li>About MongoDB
  3. 3. Dynamic querys
  4. 4. Replication
  5. 5. Sharding
  6. 6. GridFS
  7. 7. Performance</li></li></ul><li>
  8. 8. About MongoDB?<br /><ul><li>Document-oriented
  9. 9. JSON-style documents
  10. 10. Schema-free
  11. 11. Written in C++ for high performance
  12. 12. Scalable
  13. 13. MapReduce
  14. 14. Many supported platforms & languages</li></li></ul><li>Dynamic querysSelect<br />MySQL:<br />SELECT * FROM user<br />Mongo: <br />db.user.find()<br />MySQL:<br />SELECT * FROM user WHERE name = 'foobar'<br />Mongo: <br />db.user.find({'name' : 'foobar'})<br />
  15. 15. Dynamic querysInsert<br />MySQL:<br />INSERT INOT user (`name`, `age`) values ('foobar',25)<br />Mongo: <br />db.user.insert({'name' : 'foobar', 'age' : 25})<br />if you want add a column `email` on MySQL,you must :<br />ALTER TABLE user….<br />But in Mongo,you can just: <br />db.user.insert({'name' : 'foobar', 'age' : 25, 'email' : 'foo@bar.com'})<br />
  16. 16. Dynamic querysDelete<br />MySQL:<br />DELETE * FROM user<br />Mongo: <br />db.user.remove({})<br />MySQL:<br />DELETE FROM user WHERE age < 30<br />Mongo: <br />db.user.remove({'age' : {$lt : 30}})<br />$gt : > ; $gte : >= ; $lt : < ; $lte : <= ; $ne : !=<br />
  17. 17. Dynamic querysUpdate<br />MySQL:<br />UPDATE user SET `age` = 36 WHERE `name` = 'foobar'<br />Mongo: <br />db.user.update({'name' : 'foobar'}, {$set : {'age' : 36}})<br />MySQL:<br /> UPDATE user SET `age` = `age` + 3 WHERE `name` = 'foobar'<br />Mongo: <br />db.user.update({'name' : 'foobar'}, {$inc : {'age' : 3}})<br />See more @ http://tinyurl.com/yka6ras<br />
  18. 18. Dynamic querysAdvanced<br />MySQL:<br />SELECT COUNT(*) FROM user WHERE `name` = 'foobar'<br />Mongo: <br />db.user.find({'name' : 'foobar'}).count()<br />MySQL:<br /> SELECT * FROM user limit 10,20<br />Mongo: <br />db.user.find().skip(10).limit(20)<br />
  19. 19. Dynamic querysAdvanced<br />MySQL:<br />SELECT * FROM user WHERE `age` IN (25, 35,45)<br />Mongo: <br />db.user.find({'age' : {$in : [25, 35, 45]}})<br />MySQL:<br /> SELECT * FROM user limit 10,20<br />Mongo: <br />db.user.find().skip(10).limit(20)<br />
  20. 20. Dynamic querysAdvanced<br />MySQL:<br />SELECT * FROM user ORDER BY age DESC<br />Mongo: <br />db.user.find().sort({'age' : -1})<br />MySQL:<br /> SELECT DISTINCT(name) FROM user WHERE age > 20<br />Mongo: <br />db.user.distinct('name', {'age': {$lt : 20}})<br />
  21. 21. Dynamic querysAdvanced<br />MySQL:<br />SELECT name, sum(marks) FROM user GROUP BY name<br />Mongo: <br />db.user.group({<br /> key : {'name' : true},<br />cond: {'name' : 'foo'},<br /> reduce: function(obj,prev) { prev.msum += obj.marks; },<br /> initial: {msum : 0}<br /> });<br />MySQL:<br /> SELECT name FROM user WHERE age < 20<br />Mongo: <br />db.user.find('this.age < 20', {name : 1})<br />See more @ http://tinyurl.com/ykyuuwo<br />
  22. 22. So….<br />MongoDB can do almost everything that MySQL can do, and quicker & smarter<br />
  23. 23. Replication<br /><ul><li>Master-Slave Replication
  24. 24. Replica Pairs
  25. 25. Limited Master-Master Replication</li></li></ul><li>Sharding<br />
  26. 26. GridFS<br /><ul><li>files:object metadata
  27. 27. chunks:binary data</li></li></ul><li>Use GridFS In PHP<br />
  28. 28. GridFS Projects<br /><ul><li>nginx-gridfshttp://github.com/mdirolf/nginx-gridfs
  29. 29. gridfs-fusehttp://github.com/mikejs/gridfs-fuse</li></li></ul><li>Performance<br />Benchmark means nothing , but most of us like it.<br />From: http://tinyurl.com/okq7m5<br />From: http://tinyurl.com/yc3rlld<br />See more @ http://tinyurl.com/yanwn2b<br />
  30. 30. Who is using MongoDB?<br />See more @ http://tinyurl.com/dhrryw<br />
  31. 31. Thanks!<br />Q&A<br />

×