SlideShare uma empresa Scribd logo
1 de 27
MongoSF - PHP Development With MongoDB
        Presented By: Fitz Agard - LightCube Solutions LLC

                          April 30, 2010
Introductions - Who is this guy?
{ “name”: “Fitz Agard”,
  “description”: [“Developer”,”Consultant”,”Data Junkie”, “Educator”, “Engineer”],
  “location”: “New York”,
  “companies”:[
        {“name”: “LightCube Solutions”, “url”: “www.lightcubesolutions.com”}
  ],
  “urls”:[
        {“name”: “LinkedIn”, “url”: “http://www.linkedin.com/in/fitzagard”},
        {“name”: “Twitter”, “url”: “http://www.twitter.com/fitzhagard”}
  ],
  “email”: “fhagard@lightcube.us”
}




               (If the above formatting confused you please see - http://json.org/)
Why PHP Developers Should Use MongoDB?

            PHP Reasons                                                 Database Reasons
•   Enhanced Development Cycle - Itʼs no longer           •   Document-oriented storage - JSON-style documents with dynamic
    necessary to go back and forth between the Database       schemas offer simplicity and power.
    Schema and Object.                                    •   Full Index Support - Index on any attribute.
•   Easy Ramp-Up - Queries are just an array away.        •   Replication & High Availability - Mirror across LANs and WANs.
•   No Need For ORM - No Schema!                          •   Auto-Sharding - Scale horizontally without compromising functionality.
•   DBA? What DBA?                                        •   Querying - Rich, document-based queries.
•   Arrays, Array, Arrays!                                •   Fast In-Place Updates - Atomic modifiers for contention-free
                                                              performance.
                                                          •   Map/Reduce - Flexible aggregation and data processing.
                                                          •   GridFS - Store files of any size.
Mongo and PHP in a Nutshell
                 http://us.php.net/manual/en/book.mongo.php




Common Methods                    Conditional Operators
   •   find()                                     •   $ne
   •   findOne()                                  •   $in
   •   save()                                    •   $nin
   •   remove()                                  •   $mod
   •   update()                                  •   $all
   •   group()                                   •   $size
   •   limit()                                   •   $exists
   •   skip()                                    •   $type
   •   ensureIndex()                             •   $gt
   •   count()                                   •   $lt
   •   ...And More                               •   $lte
                                                 •   $gte
Mongo and PHP in a Nutshell
                                                 (Connectivity)
                                  http://us2.php.net/manual/en/mongo.connecting.php



function __construct()
{
    global $dbname, $dbuser, $dbpass;
    $this->dbname = $dbname;
    $this->dbuser = $dbuser;
    $this->dbpass = $dbpass;

    // Make the initial connection
    try {
        $this->_link = new Mongo();
        // Select the DB
        $this->db = $this->_link->selectDB($this->dbname);
        // Authenticate
        $result = $this->db->authenticate($this->dbuser, $this->dbpass);
        if ($result['ok'] == 0) {
            // Authentication failed.
            $this->error = ($result['errmsg'] == 'auth fails') ? 'Database Authentication Failure' : $result['errmsg'];
            $this->_connected = false;
        } else {
            $this->_connected = true;
        }
    } catch (Exception $e) {
        $this->error = (empty($this->error)) ? 'Database Connection Error' : $this->error;
    }
}
Mongo and PHP in a Nutshell
                                       (Simple Queries)
                           http://us2.php.net/manual/en/mongo.queries.php


	   /*
	    * SELECT * FROM students
	    * WHERE isSlacker = true
	    * AND postalCode IN (10466,10407,10704)
	    * AND gradYear BETWEEN (2010 AND 2014)
	    * ORDER BY lastName DESC
	    */
	   $collection = $this->db->students;
	   $collection->ensureIndex(array('isSlacker'=>1, 'postalCode'=>1, 'lastName'=>1, 'gradYear'=>-1));
	
	   $conditions = array('postalCode'=>array('$in'=>array(10466,10407,10704)),
	   	   	    	   	   	   'isSlacker'=>true,
	   	   	    	   	   	   'gradYear'=>array('$gt'=>2010, '$lt'=>2014));
	
	   $results = $collection->find($conditions)->sort(array('lastName'=>1));
	
	   $collection = $this->db->grades;
	
	   //SELECT count(*) FROM grades
	   $total = $collection->count();
	
	   //SELECT count(*) FROM grades WHERE grade = 90
	   $smartyPants = $collection->find(array("grade"=>90))->count();
Mongo and PHP in a Nutshell
                                              (Using GridFS)
                               http://us2.php.net/manual/en/class.mongogridfs.php

    $m = new Mongo();
	
	   //select Mongo Database
	   $db = $m->selectDB("studentsystem");
	
	   //use GridFS class for handling files
	   $grid = $db->getGridFS();
	
	   //Optional - capture the name of the uploaded file
	   $name = $_FILES['Filedata']['name'];
	
	   //load file into MongoDB and get back _id
	   $id = $grid->storeUpload('Filedata',$name);
	
	   //set a mongodate
	   $date = new MongoDate();
	
	   //Use $set to add metadata to a file
	   $metaData = array('$set' => array("comment"=>"This looks like a MongoDB Student", "date"=>$date));
	
	   //Just setting up search criteria
	   $criteria = array('_id' => $id);
	
	   //Update the document with the new info
	   $db->grid->update($criteria, $metaData);
Mongo and PHP in a Nutshell
                       (Using GridFS)


	    public function remove($criteria)
	    {
	        //Get the GridFS Object
	        $grid = $this->db->getGridFS();
	
	        //Setup some criteria to search for file
	        $id = new MongoID($criteria['_id']);
	
	        //Remove file
	        $grid->remove(array('_id'=>$id), true);
	
	        //Get lastError array
	        $errorArray = $db->lastError();
	        if ($errorArray['ok'] == 1 ) {
	            $retval = true;
	        }else{
	            //Send back the error message
	            $retval = $errorArray['err'];
	        } 	
	        return $retval;
	    }
Let’s develop a simple student information capture
         system with mongoDB and PHP!
Typical Development Cycle



          Design




  Test             Develop
Typical Design
                         Design




   (The Schema)
                  Test            Develop
Our Design
                                                                  Design




                           (The Mongo Model)
                                                           Test            Develop

             db.students             db.teachers


firstName:                  firstName:
lastName:                  lastName:
address:                   isCrazy:

    address:
    city:
    state:
    postalCode:
                                       db.courses

grades:
                           name:
    grade:                 isImpossible:
    course:                teacher:
    createdDate:
    modifiedDate:
    comment:


schedule:
    course:

sysInfo:                      Whiteboards aren’t this neat but they
                                       are just as good!
    username:
    password:


isSlacker:

gradYear:
Some Wireframes
                                                                                                                                                              Design




                                                                                                (The View)
                                                                                                                                                   Test                Develop




                                                                                                              Select Course:    - Select One -   * Required


            User Name:                                                             * Required                 Select Student:   - Select One -   * Required

              Password:     *****************                                      * Required
                                                                                                                      Grade:

            First Name:                                                            * Required

                                                                                                                                                   Submit

             Last Name:                                                            * Required




               Address:                                                            * Required



City, State, Postal Code:   City                                  - State -   Postal Code        * Required




                             Click if this student is a slacker                                                         Imagine the code for this
      Graduation Date:      mm/dd/yyyy



                                                                               Submit
Design




                                    We’re Developing
                                                                                             Test            Develop



public function studentUpdate()
	    {
	    	   $mongo_id = new MongoID($_POST['_id']);	
	    	
	    	   $data = $this->cleanupData($_POST);
	    	
	    	   $this->col->update(array("_id" => $mongo_id), array('$push' => $data));
	    	
	    	   return;
                                                  	
	    }
                                                 $_POST = '4b7c29908ead0e2e1d000000';
                                                 $data = array('firstName'=>'Fitz',
                                                 	   	    	   	   	   'lastName'=>'Agard',
                                                 	   	    	   	   	   'address'=>array(
                                                 	   	    	   	   	   	    'address'=>'123 Data Lane',
                                                 	   	    	   	   	   	    'state'=>'New York',
Letʼs assume cleanupData only removes            	   	    	   	   	   	    'postalCode'=>10704
unnecessary POST elements like the _id           	   	    	   	   	   	    ),
                                                 	   	    	   	   	   'sysInfo'=>array(
                                                 	   	    	   	   	   	    'username'=>'fhagard',
                                                 	   	    	   	   	   	    'password'=>sha1('MongoW00t')
                                                 	   	    	   	   	   	    ),
                                                 	   	    	   	   	   'isSlacker'=>true,
                                                 	   	    	   	   	   'gradYear'=>2003
                                                 	   	    	   	   	   );
Design




                                      We’re Developing
                                                                                               Test            Develop



  public function studentUpdate()
  	    {
  	    	   $mongo_id = new MongoID($_POST['_id']);	
  	    	
  	    	   $data = $this->cleanupData($_POST);
  	    	
  	    	   $this->col->update(array("_id" => $mongo_id), array('$push' => $data));
  	    	
  	    	   return;
  	    }




                                             $_POST = '4b7c29908ead0e2e1d000000';
                                             $data = array('grades'=>array(
                                                            'grade'=>'3.8',
                                                            'course'=>'4bd0dd44cc93740f3e00251c',
                                                            'createDate'=>new MongoDate()));



Donʼt forget that cleanupData only removes
 unnecessary POST elements like the _id
Design




                                                                        Test             Develop




Problem: The client called and asked why we forgot
   to collect “student infractions” in our design.


                      oops!


                              “oops” - used typically to express mild apology, surprise, or dismay.
Development back to Design
                                                                             Design




                                  (“oops” is easily fixed)
                                                                      Test            Develop
             db.students


firstName:
lastName:
address:

    address:
    city:
    state:
    postalCode:                               infractions:

grades:                                            desc:
    grade:                                         date:
    course:
    createdDate:
    modifiedDate:
    comment:


schedule:
    course:

sysInfo:

    username:
    password:
                                              Back to the whiteboard
                                        (or - napkin, omnigraffle, visio, etc)
isSlacker:

gradYear:
Another Wireframe
                                                                                                                  Design




                                               (The View - Again)
                                                                                                           Test            Develop



                                                       Infraction View



               Search for Student Input                                Search

                                                                                Last Name
                                                                                First Name
                                                                                Graduating Year
                                                                                Course



Imagine the     Editor Controls                                             A    ab

new code for
                                     Format        Font         Size

                                     B     i   u   1
                                                   2


   this.
                                                   3



                      Textarea       enter text




                     Date Selector       __ / __ / ____

                                      Select a date range




                                                                                                  Submit
Design right back to Development
                                                                                              Design




                                 (The Fix! Do you see it?)
                                                                                     Test              Develop




         public function studentUpdate()
         	   {
         	   	    $mongo_id = new MongoID($_POST['_id']);	
         	   	
         	   	    $data = $this->cleanupData($_POST);
         	   	
         	   	    $this->col->update(array("_id" => $mongo_id), array('$push' => $data));
         	   	
         	   	    return;
         	   }




 $_POST['_id'] = '4b7c29908ead0e2e1d000000';
 $data = array('infractions'=> array('desc'=>'Caught Sharding', 'date'=> new MongoDate()));




Answer: The only thing that changed was the view in the last slide.
                     This code is the same!
Design and Development In Summary



Our Classes/Methods/Views made the schema
                  NoSQL
                  NoORM
          Arrays! Arrays! Arrays!
Design




                Let’s Test
                                      Test            Develop




What does MongoDB have to do with testing?
Design




                 Let’s Test
                                           Test            Develop




Isn’t it a good idea to run unit tests often?

    Where do you store the results?
Idea: PHPUnit to Mongo
                                                                                    Design




                                    (Test Logging)
                                                                             Test            Develop




                                                                          Test logs can
                                                                          go in Mongo




Clipping from: http://www.phpunit.de/manual/current/en/logging.html#logging.json
Wait, there is MORE!
Cursors
 MongoDates
                     Indexes                   MapReduce

                ...Just to name a few...
     Sharding
                                           Exceptions

MongoBinData
                                                MongoCode
            MongoRegex
No more time.


            Go here for more:
http://us.php.net/manual/en/book.mongo.php
         http://www.mongodb.org
    http://www.lightcubesolutions.com
{ “type”: “Conclusion”,
  “date”: new Date('04-30-2010'),
  “comments”: [“Thank You”,”Have Fun Developing”],
  “location”: “San Francisco”,
  “speaker”: “Fitz H. Agard”,
  “contact”: “fhagard@lightcube.us”
}

Mais conteúdo relacionado

Mais procurados

NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!Daniel Cousineau
 
jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentationguestcf600a
 
Banishing Loops with Functional Programming in PHP
Banishing Loops with Functional Programming in PHPBanishing Loops with Functional Programming in PHP
Banishing Loops with Functional Programming in PHPDavid Hayes
 
Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Ralph Schindler
 
Recent Changes to jQuery's Internals
Recent Changes to jQuery's InternalsRecent Changes to jQuery's Internals
Recent Changes to jQuery's Internalsjeresig
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know Norberto Leite
 
Database madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemyDatabase madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemyJaime Buelta
 
CodeIgniter Class Reference
CodeIgniter Class ReferenceCodeIgniter Class Reference
CodeIgniter Class ReferenceJamshid Hashimi
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapHoward Lewis Ship
 
Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Karsten Dambekalns
 
Advanced Django ORM techniques
Advanced Django ORM techniquesAdvanced Django ORM techniques
Advanced Django ORM techniquesDaniel Roseman
 
Therapeutic refactoring
Therapeutic refactoringTherapeutic refactoring
Therapeutic refactoringkytrinyx
 

Mais procurados (17)

NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
NOSQL101, Or: How I Learned To Stop Worrying And Love The Mongo!
 
jQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20PresentationjQuery%20on%20Rails%20Presentation
jQuery%20on%20Rails%20Presentation
 
Potential Friend Finder
Potential Friend FinderPotential Friend Finder
Potential Friend Finder
 
Banishing Loops with Functional Programming in PHP
Banishing Loops with Functional Programming in PHPBanishing Loops with Functional Programming in PHP
Banishing Loops with Functional Programming in PHP
 
Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2Zend Framework 1 + Doctrine 2
Zend Framework 1 + Doctrine 2
 
Django Pro ORM
Django Pro ORMDjango Pro ORM
Django Pro ORM
 
Recent Changes to jQuery's Internals
Recent Changes to jQuery's InternalsRecent Changes to jQuery's Internals
Recent Changes to jQuery's Internals
 
MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know MongoDB + Java - Everything you need to know
MongoDB + Java - Everything you need to know
 
Database madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemyDatabase madness with_mongoengine_and_sql_alchemy
Database madness with_mongoengine_and_sql_alchemy
 
Dart
DartDart
Dart
 
CodeIgniter Class Reference
CodeIgniter Class ReferenceCodeIgniter Class Reference
CodeIgniter Class Reference
 
Django - sql alchemy - jquery
Django - sql alchemy - jqueryDjango - sql alchemy - jquery
Django - sql alchemy - jquery
 
Modern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter BootstrapModern Application Foundations: Underscore and Twitter Bootstrap
Modern Application Foundations: Underscore and Twitter Bootstrap
 
Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3Transparent Object Persistence with FLOW3
Transparent Object Persistence with FLOW3
 
Advanced Django ORM techniques
Advanced Django ORM techniquesAdvanced Django ORM techniques
Advanced Django ORM techniques
 
Therapeutic refactoring
Therapeutic refactoringTherapeutic refactoring
Therapeutic refactoring
 
Spock and Geb
Spock and GebSpock and Geb
Spock and Geb
 

Semelhante a PHP Development with MongoDB (Fitz Agard)

mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introductionTse-Ching Ho
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Editionddiers
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Jonathan Felch
 
MongoDB a document store that won't let you down.
MongoDB a document store that won't let you down.MongoDB a document store that won't let you down.
MongoDB a document store that won't let you down.Nurul Ferdous
 
Mongo NYC PHP Development
Mongo NYC PHP Development Mongo NYC PHP Development
Mongo NYC PHP Development Fitz Agard
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVCAlive Kuo
 
This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP formatForest Mars
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQLddiers
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::ManagerJay Shirley
 
Real World Optimization
Real World OptimizationReal World Optimization
Real World OptimizationDavid Golden
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMetatagg Solutions
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHPRob Knight
 
gDayX - Advanced angularjs
gDayX - Advanced angularjsgDayX - Advanced angularjs
gDayX - Advanced angularjsgdgvietnam
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDoug Green
 

Semelhante a PHP Development with MongoDB (Fitz Agard) (20)

mongodb-introduction
mongodb-introductionmongodb-introduction
mongodb-introduction
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Edition
 
Full metal mongo
Full metal mongoFull metal mongo
Full metal mongo
 
Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)Groovy On Trading Desk (2010)
Groovy On Trading Desk (2010)
 
MongoDB a document store that won't let you down.
MongoDB a document store that won't let you down.MongoDB a document store that won't let you down.
MongoDB a document store that won't let you down.
 
Mongo NYC PHP Development
Mongo NYC PHP Development Mongo NYC PHP Development
Mongo NYC PHP Development
 
[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC[Coscup 2012] JavascriptMVC
[Coscup 2012] JavascriptMVC
 
Rails with mongodb
Rails with mongodbRails with mongodb
Rails with mongodb
 
This upload requires better support for ODP format
This upload requires better support for ODP formatThis upload requires better support for ODP format
This upload requires better support for ODP format
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQL
 
Mongo-Drupal
Mongo-DrupalMongo-Drupal
Mongo-Drupal
 
Building Better Applications with Data::Manager
Building Better Applications with Data::ManagerBuilding Better Applications with Data::Manager
Building Better Applications with Data::Manager
 
Real World Optimization
Real World OptimizationReal World Optimization
Real World Optimization
 
Mongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg SolutionsMongo Presentation by Metatagg Solutions
Mongo Presentation by Metatagg Solutions
 
Object Relational Mapping in PHP
Object Relational Mapping in PHPObject Relational Mapping in PHP
Object Relational Mapping in PHP
 
Having Fun with Play
Having Fun with PlayHaving Fun with Play
Having Fun with Play
 
Latinoware
LatinowareLatinoware
Latinoware
 
gDayX - Advanced angularjs
gDayX - Advanced angularjsgDayX - Advanced angularjs
gDayX - Advanced angularjs
 
DrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and DrupalDrupalCon Chicago Practical MongoDB and Drupal
DrupalCon Chicago Practical MongoDB and Drupal
 
What's new in Django 1.2?
What's new in Django 1.2?What's new in Django 1.2?
What's new in Django 1.2?
 

Mais de MongoSF

Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) 
Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) 
Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) MongoSF
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)MongoSF
 
C# Development (Sam Corder)
C# Development (Sam Corder)C# Development (Sam Corder)
C# Development (Sam Corder)MongoSF
 
Flexible Event Tracking (Paul Gebheim)
Flexible Event Tracking (Paul Gebheim)Flexible Event Tracking (Paul Gebheim)
Flexible Event Tracking (Paul Gebheim)MongoSF
 
Administration (Eliot Horowitz)
Administration (Eliot Horowitz)Administration (Eliot Horowitz)
Administration (Eliot Horowitz)MongoSF
 
Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)MongoSF
 
MongoHQ (Jason McCay & Ben Wyrosdick)
MongoHQ (Jason McCay & Ben Wyrosdick)MongoHQ (Jason McCay & Ben Wyrosdick)
MongoHQ (Jason McCay & Ben Wyrosdick)MongoSF
 
Administration
AdministrationAdministration
AdministrationMongoSF
 
Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)MongoSF
 
Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)MongoSF
 
Implementing MongoDB at Shutterfly (Kenny Gorman)
Implementing MongoDB at Shutterfly (Kenny Gorman)Implementing MongoDB at Shutterfly (Kenny Gorman)
Implementing MongoDB at Shutterfly (Kenny Gorman)MongoSF
 
Debugging Ruby (Aman Gupta)
Debugging Ruby (Aman Gupta)Debugging Ruby (Aman Gupta)
Debugging Ruby (Aman Gupta)MongoSF
 
Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)MongoSF
 
MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)MongoSF
 
Zero to Mongo in 60 Hours
Zero to Mongo in 60 HoursZero to Mongo in 60 Hours
Zero to Mongo in 60 HoursMongoSF
 
Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)
Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)
Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)MongoSF
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)MongoSF
 
Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...
Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...
Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...MongoSF
 
From MySQL to MongoDB at Wordnik (Tony Tam)
From MySQL to MongoDB at Wordnik (Tony Tam)From MySQL to MongoDB at Wordnik (Tony Tam)
From MySQL to MongoDB at Wordnik (Tony Tam)MongoSF
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)MongoSF
 

Mais de MongoSF (20)

Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) 
Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) 
Webinar: Typische MongoDB Anwendungsfälle (Common MongoDB Use Cases) 
 
Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)Schema design with MongoDB (Dwight Merriman)
Schema design with MongoDB (Dwight Merriman)
 
C# Development (Sam Corder)
C# Development (Sam Corder)C# Development (Sam Corder)
C# Development (Sam Corder)
 
Flexible Event Tracking (Paul Gebheim)
Flexible Event Tracking (Paul Gebheim)Flexible Event Tracking (Paul Gebheim)
Flexible Event Tracking (Paul Gebheim)
 
Administration (Eliot Horowitz)
Administration (Eliot Horowitz)Administration (Eliot Horowitz)
Administration (Eliot Horowitz)
 
Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)Ruby Development and MongoMapper (John Nunemaker)
Ruby Development and MongoMapper (John Nunemaker)
 
MongoHQ (Jason McCay & Ben Wyrosdick)
MongoHQ (Jason McCay & Ben Wyrosdick)MongoHQ (Jason McCay & Ben Wyrosdick)
MongoHQ (Jason McCay & Ben Wyrosdick)
 
Administration
AdministrationAdministration
Administration
 
Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)Sharding with MongoDB (Eliot Horowitz)
Sharding with MongoDB (Eliot Horowitz)
 
Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)Practical Ruby Projects (Alex Sharp)
Practical Ruby Projects (Alex Sharp)
 
Implementing MongoDB at Shutterfly (Kenny Gorman)
Implementing MongoDB at Shutterfly (Kenny Gorman)Implementing MongoDB at Shutterfly (Kenny Gorman)
Implementing MongoDB at Shutterfly (Kenny Gorman)
 
Debugging Ruby (Aman Gupta)
Debugging Ruby (Aman Gupta)Debugging Ruby (Aman Gupta)
Debugging Ruby (Aman Gupta)
 
Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)Indexing and Query Optimizer (Aaron Staple)
Indexing and Query Optimizer (Aaron Staple)
 
MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)MongoDB Replication (Dwight Merriman)
MongoDB Replication (Dwight Merriman)
 
Zero to Mongo in 60 Hours
Zero to Mongo in 60 HoursZero to Mongo in 60 Hours
Zero to Mongo in 60 Hours
 
Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)
Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)
Building a Mongo DSL in Scala at Hot Potato (Lincoln Hochberg)
 
Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)Java Development with MongoDB (James Williams)
Java Development with MongoDB (James Williams)
 
Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...
Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...
Real time ecommerce analytics with MongoDB at Gilt Groupe (Michael Bryzek & M...
 
From MySQL to MongoDB at Wordnik (Tony Tam)
From MySQL to MongoDB at Wordnik (Tony Tam)From MySQL to MongoDB at Wordnik (Tony Tam)
From MySQL to MongoDB at Wordnik (Tony Tam)
 
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
Map/reduce, geospatial indexing, and other cool features (Kristina Chodorow)
 

Último

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?Igalia
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 

Último (20)

From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 

PHP Development with MongoDB (Fitz Agard)

  • 1. MongoSF - PHP Development With MongoDB Presented By: Fitz Agard - LightCube Solutions LLC April 30, 2010
  • 2. Introductions - Who is this guy? { “name”: “Fitz Agard”, “description”: [“Developer”,”Consultant”,”Data Junkie”, “Educator”, “Engineer”], “location”: “New York”, “companies”:[ {“name”: “LightCube Solutions”, “url”: “www.lightcubesolutions.com”} ], “urls”:[ {“name”: “LinkedIn”, “url”: “http://www.linkedin.com/in/fitzagard”}, {“name”: “Twitter”, “url”: “http://www.twitter.com/fitzhagard”} ], “email”: “fhagard@lightcube.us” } (If the above formatting confused you please see - http://json.org/)
  • 3. Why PHP Developers Should Use MongoDB? PHP Reasons Database Reasons • Enhanced Development Cycle - Itʼs no longer • Document-oriented storage - JSON-style documents with dynamic necessary to go back and forth between the Database schemas offer simplicity and power. Schema and Object. • Full Index Support - Index on any attribute. • Easy Ramp-Up - Queries are just an array away. • Replication & High Availability - Mirror across LANs and WANs. • No Need For ORM - No Schema! • Auto-Sharding - Scale horizontally without compromising functionality. • DBA? What DBA? • Querying - Rich, document-based queries. • Arrays, Array, Arrays! • Fast In-Place Updates - Atomic modifiers for contention-free performance. • Map/Reduce - Flexible aggregation and data processing. • GridFS - Store files of any size.
  • 4. Mongo and PHP in a Nutshell http://us.php.net/manual/en/book.mongo.php Common Methods Conditional Operators • find() • $ne • findOne() • $in • save() • $nin • remove() • $mod • update() • $all • group() • $size • limit() • $exists • skip() • $type • ensureIndex() • $gt • count() • $lt • ...And More • $lte • $gte
  • 5. Mongo and PHP in a Nutshell (Connectivity) http://us2.php.net/manual/en/mongo.connecting.php function __construct() { global $dbname, $dbuser, $dbpass; $this->dbname = $dbname; $this->dbuser = $dbuser; $this->dbpass = $dbpass; // Make the initial connection try { $this->_link = new Mongo(); // Select the DB $this->db = $this->_link->selectDB($this->dbname); // Authenticate $result = $this->db->authenticate($this->dbuser, $this->dbpass); if ($result['ok'] == 0) { // Authentication failed. $this->error = ($result['errmsg'] == 'auth fails') ? 'Database Authentication Failure' : $result['errmsg']; $this->_connected = false; } else { $this->_connected = true; } } catch (Exception $e) { $this->error = (empty($this->error)) ? 'Database Connection Error' : $this->error; } }
  • 6. Mongo and PHP in a Nutshell (Simple Queries) http://us2.php.net/manual/en/mongo.queries.php /* * SELECT * FROM students * WHERE isSlacker = true * AND postalCode IN (10466,10407,10704) * AND gradYear BETWEEN (2010 AND 2014) * ORDER BY lastName DESC */ $collection = $this->db->students; $collection->ensureIndex(array('isSlacker'=>1, 'postalCode'=>1, 'lastName'=>1, 'gradYear'=>-1)); $conditions = array('postalCode'=>array('$in'=>array(10466,10407,10704)), 'isSlacker'=>true, 'gradYear'=>array('$gt'=>2010, '$lt'=>2014)); $results = $collection->find($conditions)->sort(array('lastName'=>1)); $collection = $this->db->grades; //SELECT count(*) FROM grades $total = $collection->count(); //SELECT count(*) FROM grades WHERE grade = 90 $smartyPants = $collection->find(array("grade"=>90))->count();
  • 7. Mongo and PHP in a Nutshell (Using GridFS) http://us2.php.net/manual/en/class.mongogridfs.php $m = new Mongo(); //select Mongo Database $db = $m->selectDB("studentsystem"); //use GridFS class for handling files $grid = $db->getGridFS(); //Optional - capture the name of the uploaded file $name = $_FILES['Filedata']['name']; //load file into MongoDB and get back _id $id = $grid->storeUpload('Filedata',$name); //set a mongodate $date = new MongoDate(); //Use $set to add metadata to a file $metaData = array('$set' => array("comment"=>"This looks like a MongoDB Student", "date"=>$date)); //Just setting up search criteria $criteria = array('_id' => $id); //Update the document with the new info $db->grid->update($criteria, $metaData);
  • 8. Mongo and PHP in a Nutshell (Using GridFS) public function remove($criteria) { //Get the GridFS Object $grid = $this->db->getGridFS(); //Setup some criteria to search for file $id = new MongoID($criteria['_id']); //Remove file $grid->remove(array('_id'=>$id), true); //Get lastError array $errorArray = $db->lastError(); if ($errorArray['ok'] == 1 ) { $retval = true; }else{ //Send back the error message $retval = $errorArray['err']; } return $retval; }
  • 9. Let’s develop a simple student information capture system with mongoDB and PHP!
  • 10. Typical Development Cycle Design Test Develop
  • 11. Typical Design Design (The Schema) Test Develop
  • 12. Our Design Design (The Mongo Model) Test Develop db.students db.teachers firstName: firstName: lastName: lastName: address: isCrazy: address: city: state: postalCode: db.courses grades: name: grade: isImpossible: course: teacher: createdDate: modifiedDate: comment: schedule: course: sysInfo: Whiteboards aren’t this neat but they are just as good! username: password: isSlacker: gradYear:
  • 13. Some Wireframes Design (The View) Test Develop Select Course: - Select One - * Required User Name: * Required Select Student: - Select One - * Required Password: ***************** * Required Grade: First Name: * Required Submit Last Name: * Required Address: * Required City, State, Postal Code: City - State - Postal Code * Required Click if this student is a slacker Imagine the code for this Graduation Date: mm/dd/yyyy Submit
  • 14. Design We’re Developing Test Develop public function studentUpdate() { $mongo_id = new MongoID($_POST['_id']); $data = $this->cleanupData($_POST); $this->col->update(array("_id" => $mongo_id), array('$push' => $data)); return; } $_POST = '4b7c29908ead0e2e1d000000'; $data = array('firstName'=>'Fitz', 'lastName'=>'Agard', 'address'=>array( 'address'=>'123 Data Lane', 'state'=>'New York', Letʼs assume cleanupData only removes 'postalCode'=>10704 unnecessary POST elements like the _id ), 'sysInfo'=>array( 'username'=>'fhagard', 'password'=>sha1('MongoW00t') ), 'isSlacker'=>true, 'gradYear'=>2003 );
  • 15. Design We’re Developing Test Develop public function studentUpdate() { $mongo_id = new MongoID($_POST['_id']); $data = $this->cleanupData($_POST); $this->col->update(array("_id" => $mongo_id), array('$push' => $data)); return; } $_POST = '4b7c29908ead0e2e1d000000'; $data = array('grades'=>array( 'grade'=>'3.8', 'course'=>'4bd0dd44cc93740f3e00251c', 'createDate'=>new MongoDate())); Donʼt forget that cleanupData only removes unnecessary POST elements like the _id
  • 16. Design Test Develop Problem: The client called and asked why we forgot to collect “student infractions” in our design. oops! “oops” - used typically to express mild apology, surprise, or dismay.
  • 17. Development back to Design Design (“oops” is easily fixed) Test Develop db.students firstName: lastName: address: address: city: state: postalCode: infractions: grades: desc: grade: date: course: createdDate: modifiedDate: comment: schedule: course: sysInfo: username: password: Back to the whiteboard (or - napkin, omnigraffle, visio, etc) isSlacker: gradYear:
  • 18. Another Wireframe Design (The View - Again) Test Develop Infraction View Search for Student Input Search Last Name First Name Graduating Year Course Imagine the Editor Controls A ab new code for Format Font Size B i u 1 2 this. 3 Textarea enter text Date Selector __ / __ / ____ Select a date range Submit
  • 19. Design right back to Development Design (The Fix! Do you see it?) Test Develop public function studentUpdate() { $mongo_id = new MongoID($_POST['_id']); $data = $this->cleanupData($_POST); $this->col->update(array("_id" => $mongo_id), array('$push' => $data)); return; } $_POST['_id'] = '4b7c29908ead0e2e1d000000'; $data = array('infractions'=> array('desc'=>'Caught Sharding', 'date'=> new MongoDate())); Answer: The only thing that changed was the view in the last slide. This code is the same!
  • 20. Design and Development In Summary Our Classes/Methods/Views made the schema NoSQL NoORM Arrays! Arrays! Arrays!
  • 21. Design Let’s Test Test Develop What does MongoDB have to do with testing?
  • 22. Design Let’s Test Test Develop Isn’t it a good idea to run unit tests often? Where do you store the results?
  • 23. Idea: PHPUnit to Mongo Design (Test Logging) Test Develop Test logs can go in Mongo Clipping from: http://www.phpunit.de/manual/current/en/logging.html#logging.json
  • 24. Wait, there is MORE!
  • 25. Cursors MongoDates Indexes MapReduce ...Just to name a few... Sharding Exceptions MongoBinData MongoCode MongoRegex
  • 26. No more time. Go here for more: http://us.php.net/manual/en/book.mongo.php http://www.mongodb.org http://www.lightcubesolutions.com
  • 27. { “type”: “Conclusion”, “date”: new Date('04-30-2010'), “comments”: [“Thank You”,”Have Fun Developing”], “location”: “San Francisco”, “speaker”: “Fitz H. Agard”, “contact”: “fhagard@lightcube.us” }

Notas do Editor