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


                  Nurul Ferdous
     Platform Architect at Tasawr Interactive
        @ferdous, http://dynamicguy.com
Web 1.0
Web 2.0
MySQL problem
Resolution
NoSQL vs RDBMS

          NoSQL                        RDBMS
● Schema-free              ●   Relational schema
                           ●   Scalable reads
● Scalable writes/reads
                           ●   Custom high-availability
● Auto high-availability   ●   Flexible queries
● Limited queries          ●   Consistency
● Eventual Consistency     ●   ACID
● BASE
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)       $db->users->insert(array("a" => 1, "b" => 1));
INSERT INTO USERS VALUES(1,1)                 $db->users->find(array(), array("a" => 1, "b" => 1));
SELECT a,b FROM users                         $db->users->find(array("age" => 33));
SELECT * FROM users WHERE age=33              $db->users->find(array("age" => 33), array("a" => 1,
SELECT a,b FROM users WHERE age=33            "b" => 1));
SELECT a,b FROM users WHERE age=33 ORDER      $db->users->find(array("age" => 33), array("a" => 1,
BY name                                       "b" => 1))->sort(array("name" => 1));
SELECT * FROM users WHERE age>33              $db->users->find(array("age" => array('$gt' => 33)));
SELECT * FROM users WHERE age<33              $db->users->find(array("age" => array('$lt' => 33)));
SELECT * FROM users WHERE name LIKE "%Joe%"   $db->users->find(array("name" => new MongoRegex
                                              ("/Joe/")));
SELECT * FROM users WHERE name LIKE "Joe%"
                                              $db->users->find(array("name" => new MongoRegex
SELECT * FROM users WHERE age>33 AND
                                              ("/^Joe/")));
age<=40
                                              $db->users->find(array("age" => array('$gt' => 33,
SELECT * FROM users ORDER BY name DESC
                                              '$lte' => 40)));
                                              $db->users->find()->sort(array("name" => -1));
Map Reduce
Map Reduce
Question?

● I am
  ○ Nurul Ferdous <nurul@ferdo.us>
  ○ @ferdous
  ○ http://dynamicguy.com/
 
● Try it out
  ○ http://www.mongodb.org/downloads#
  ○ http://www.php.net/manual/en/book.mongo.php

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

  • 1.
    MongoDB, a documentstore that won't let you down Nurul Ferdous Platform Architect at Tasawr Interactive @ferdous, http://dynamicguy.com
  • 2.
  • 3.
  • 4.
  • 5.
  • 6.
    NoSQL vs RDBMS NoSQL RDBMS ● Schema-free ● Relational schema ● Scalable reads ● Scalable writes/reads ● Custom high-availability ● Auto high-availability ● Flexible queries ● Limited queries ● Consistency ● Eventual Consistency ● ACID ● BASE
  • 7.
  • 8.
  • 9.
  • 10.
    Installing MongoDB server ubuntuway ● 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.
  • 11.
  • 12.
  • 13.
  • 14.
  • 15.
  • 16.
  • 17.
  • 18.
  • 19.
  • 20.
    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  
  • 21.
  • 22.
  • 23.
  • 24.
    SQL to MongoDB CREATETABLE USERS (a Number, b Number) $db->users->insert(array("a" => 1, "b" => 1)); INSERT INTO USERS VALUES(1,1) $db->users->find(array(), array("a" => 1, "b" => 1)); SELECT a,b FROM users $db->users->find(array("age" => 33)); SELECT * FROM users WHERE age=33 $db->users->find(array("age" => 33), array("a" => 1, SELECT a,b FROM users WHERE age=33 "b" => 1)); SELECT a,b FROM users WHERE age=33 ORDER $db->users->find(array("age" => 33), array("a" => 1, BY name "b" => 1))->sort(array("name" => 1)); SELECT * FROM users WHERE age>33 $db->users->find(array("age" => array('$gt' => 33))); SELECT * FROM users WHERE age<33 $db->users->find(array("age" => array('$lt' => 33))); SELECT * FROM users WHERE name LIKE "%Joe%" $db->users->find(array("name" => new MongoRegex ("/Joe/"))); SELECT * FROM users WHERE name LIKE "Joe%" $db->users->find(array("name" => new MongoRegex SELECT * FROM users WHERE age>33 AND ("/^Joe/"))); age<=40 $db->users->find(array("age" => array('$gt' => 33, SELECT * FROM users ORDER BY name DESC '$lte' => 40))); $db->users->find()->sort(array("name" => -1));
  • 25.
  • 26.
  • 27.
    Question? ● I am ○ Nurul Ferdous <nurul@ferdo.us> ○ @ferdous ○ http://dynamicguy.com/   ● Try it out ○ http://www.mongodb.org/downloads# ○ http://www.php.net/manual/en/book.mongo.php