MongoDB a document store that won't let you down.

27
MongoDB, a document store that won't let you down Nurul Ferdous Platform Architect at Tasawr Interactive @ferdous, http://dynamicguy.com

description

This talk was given by me at phpXperts seminar 2011 in UIU dhaka.

Transcript of MongoDB a document store that won't let you down.

Page 1: MongoDB a document store that won't let you down.

MongoDB, a document store that won't let you down

Nurul FerdousPlatform Architect at Tasawr Interactive

@ferdous, http://dynamicguy.com

Page 2: MongoDB a document store that won't let you down.

Web 1.0

Page 3: MongoDB a document store that won't let you down.

Web 2.0

Page 4: MongoDB a document store that won't let you down.

MySQL problem

Page 5: MongoDB a document store that won't let you down.

Resolution

Page 6: MongoDB a document store that won't let you down.

NoSQL vs RDBMS

NoSQL

● Schema-free● Scalable writes/reads● Auto high-availability● Limited queries● Eventual Consistency● BASE

RDBMS● Relational schema● Scalable reads● Custom high-availability ● Flexible queries● Consistency● ACID

Page 7: MongoDB a document store that won't let you down.

Who else there?

Page 8: MongoDB a document store that won't let you down.

CAP theorem

Page 9: MongoDB a document store that won't let you down.

MongoDB in CAP

Page 10: MongoDB a document store that won't let you down.

Installing MongoDB server

ubuntu way● sudo apt-key adv --keyserver keyserver.ubuntu.com --recv 7F0CEB10● deb http://downloads-distro.mongodb.org/repo/ubuntu-upstart dist

10gen● sudo apt-get update● sudo apt-get install mongodb-10gen

 

windows (shame on you!) way● Download - http://mongodb.org/downloads● Unzip● Create a data directory● Run and connect to the server

 p.s.: 32bit is limited to 2.5gb size limit.

Page 11: MongoDB a document store that won't let you down.

Understanding MongoDB

Page 12: MongoDB a document store that won't let you down.

Understanding MongoDB

Page 13: MongoDB a document store that won't let you down.

Understanding MongoDB

Page 14: MongoDB a document store that won't let you down.

Understanding MongoDB

Page 15: MongoDB a document store that won't let you down.

Understanding MongoDB

Page 16: MongoDB a document store that won't let you down.

Understanding MongoDB

Page 17: MongoDB a document store that won't let you down.

Understanding MongoDB

Page 18: MongoDB a document store that won't let you down.

Understanding MongoDB

Page 19: MongoDB a document store that won't let you down.

Understanding MongoDB

Page 20: MongoDB a document store that won't let you down.

PHP and MongoDB

Installation     or `sudo pecl install mongo` To load the extension, add a line in php.ini:`extension=mongo.so` # of course without quote

 

Page 21: MongoDB a document store that won't let you down.

Connection

Page 22: MongoDB a document store that won't let you down.

Query

Page 23: MongoDB a document store that won't let you down.

CRUD

Page 24: MongoDB a document store that won't let you down.

SQL to MongoDB

CREATE TABLE USERS (a Number, b Number)INSERT INTO USERS VALUES(1,1)SELECT a,b FROM usersSELECT * FROM users WHERE age=33SELECT a,b FROM users WHERE age=33SELECT a,b FROM users WHERE age=33 ORDER BY nameSELECT * FROM users WHERE age>33SELECT * FROM users WHERE age<33SELECT * FROM users WHERE name LIKE "%Joe%"SELECT * FROM users WHERE name LIKE "Joe%"SELECT * FROM users WHERE age>33 AND age<=40SELECT * FROM users ORDER BY name DESC

$db->users->insert(array("a" => 1, "b" => 1));$db->users->find(array(), array("a" => 1, "b" => 1));$db->users->find(array("age" => 33));$db->users->find(array("age" => 33), array("a" => 1, "b" => 1));$db->users->find(array("age" => 33), array("a" => 1, "b" => 1))->sort(array("name" => 1));$db->users->find(array("age" => array('$gt' => 33)));$db->users->find(array("age" => array('$lt' => 33)));$db->users->find(array("name" => new MongoRegex("/Joe/")));$db->users->find(array("name" => new MongoRegex("/^Joe/")));$db->users->find(array("age" => array('$gt' => 33, '$lte' => 40)));$db->users->find()->sort(array("name" => -1));

Page 25: MongoDB a document store that won't let you down.

Map Reduce

Page 26: MongoDB a document store that won't let you down.

Map Reduce

Page 27: MongoDB a document store that won't let you down.

Question?

● I am ○ Nurul Ferdous <[email protected]> ○ @ferdous○ http://dynamicguy.com/

 ● Try it out

○ http://www.mongodb.org/downloads#○ http://www.php.net/manual/en/book.mongo.php