MongoDB, a document store that won't let you down
Nurul FerdousPlatform Architect at Tasawr Interactive
@ferdous, http://dynamicguy.com
Web 1.0
Web 2.0
MySQL problem
Resolution
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
Who else there?
CAP theorem
MongoDB in CAP
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.
Understanding MongoDB
Understanding MongoDB
Understanding MongoDB
Understanding MongoDB
Understanding MongoDB
Understanding MongoDB
Understanding MongoDB
Understanding MongoDB
Understanding MongoDB
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
Connection
Query
CRUD
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));
Map Reduce
Map Reduce
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