SlideShare a Scribd company logo
1 of 73
Download to read offline
Doctrine
               MongoDB Object Document Mapper (ODM)




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
What is Doctrine?



Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
What is Doctrine?
  •    Open source PHP project started in 2006

  •    Relational database abstraction layer.
        •     mysql, oracle, pgsql, sqlite, etc.



  •    Object persistence layers for RDBMS,
       MongoDB, etc.

  •    Other database related functionalities.
                         http://www.doctrine-project.org
Doctrine MongoDB ODM          www.doctrine-project.org   www.sensiolabs.org
What is MongoDB?
  •    Key-Value document based storage
       system.

  •    Bridge between traditional relational
       databases and key-value data stores.



                       http://www.mongodb.org

Doctrine MongoDB ODM     www.doctrine-project.org   www.sensiolabs.org
Terminology

                       RDBMS                                MongoDB
                       Database                                    Database

                        Table                                     Collection

                        Row                                       Document




Doctrine MongoDB ODM        www.doctrine-project.org   www.sensiolabs.org
Using MongoDB in PHP



Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Connecting


       $mongo = new Mongo('mongodb://localhost');




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Selecting Databases


       $mongo = new Mongo('mongodb://localhost');
       $db = $mongo->selectDB('dbname');




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Selecting Collections


       $mongo = new Mongo('mongodb://localhost');
       $db = $mongo->selectDB('dbname');
       $coll = $db->selectCollection('users');




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Inserting Documents
                 Insert a new user document and echo the newly generated id


       $user = array(
           'username' => 'jwage',
           'password' => md5('changeme')
           'active' => true
       );
       $coll->insert($user);

       echo $user['_id'];




Doctrine MongoDB ODM        www.doctrine-project.org   www.sensiolabs.org
Updating Documents
                Update username and password and save the whole document




       $user = $coll->findOne(array('username' => 'jwage'));
       $user['username'] = 'jonwage';
       $user['password'] = md5('newpassword');
       $coll->save($user);




Doctrine MongoDB ODM      www.doctrine-project.org   www.sensiolabs.org
Atomic Updates
  •    Faster than saving the entire document.

  •    Safer than updating the entire document.

  •    Updates are done in place and are atomic.




Doctrine MongoDB ODM     www.doctrine-project.org   www.sensiolabs.org
Atomic Updates
                   Update username and password where username is jwage



       $coll->update(array(
           'username' => 'jwage'
       ), array(
           '$set' => array(
               'username' => 'jonwage',
               'password' => md5('newpassword')
           )
       ));




Doctrine MongoDB ODM       www.doctrine-project.org   www.sensiolabs.org
Atomic Updates
            Many other atomic operators exist for manipulating a documents data




  •    $inc - increments field by the number value
  •    $set - sets field to value
  •    $unset - deletes a given field
  •    $push - appends value to an array
  •    $pushAll - appends multiple values to an array
  •    $addToSet - appends multiple values to an array that don’t already exist in the
       array
  •    $pop - removes the last element in an array
  •    $pull - removes all occurrences of a value from an array
  •    $pullAll - removes all occurrences of multiple values from an array




Doctrine MongoDB ODM       www.doctrine-project.org   www.sensiolabs.org
Removing Documents


       $coll->remove(array('username' => 'jwage'));




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Doctrine + MongoDB



Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
DocumentManager
  •    Abstraction on top of the PHP Mongo
       class

  •    Manages the persistent state of PHP
       objects

  •    Implements UnitOfWork for change
       tracking
                       http://martinfowler.com/eaaCatalog/unitOfWork.html

Doctrine MongoDB ODM       www.doctrine-project.org     www.sensiolabs.org
Document States
  •    A NEW document instance has no persistent identity, and is not yet
       associated with a DocumentManager (i.e. those just created with the
       "new" operator).

  •    A MANAGED document instance is an instance with a persistent
       identity that is associated with an DocumentManager and whose
       persistence is thus managed.

  •    A DETACHED document instance is an instance with a persistent
       identity that is not (or no longer) associated with an
       DocumentManager.

  •    A REMOVED document instance is an instance with a persistent
       identity, associated with an DocumentManager, that will be removed
       from the database upon transaction commit.


Doctrine MongoDB ODM    www.doctrine-project.org   www.sensiolabs.org
DocumentManager
           Create your DocumentManager instance for managing object persistence



       $config = new DoctrineODMMongoDBConfiguration();
       $config->setMetadataCacheImpl(new DoctrineCommonCacheArrayCache);
       $driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Documents"));
       $config->setMetadataDriverImpl($driverImpl);

       $config->setProxyDir(__DIR__ . '/Proxies');
       $config->setProxyNamespace('Proxies');

       $dm = DoctrineORMDocumentManager::create($mongo, $config);




                         Wraps around existing $mongo connection




Doctrine MongoDB ODM       www.doctrine-project.org   www.sensiolabs.org
Defining Document
                       A document is just a regular ole’ PHP class

                                class User
                                {
                                    private $id;
                                    private $username;
                                    private $password;

                                    public function getId()
                                    {
                                        return $this->id;
                                    }

                                    public function getUsername()
                                    {
                                        return $this->username;
                                    }

                                    public function setUsername($username)
                                    {
                                        $this->username = $username;
                                    }

                                    public function getPassword()
                                    {
                                        return $this->password;
                                    }

                                    public function setPassword($password)
                                    {
                                        $this->password = md5($password);
                                    }
                                }




Doctrine MongoDB ODM     www.doctrine-project.org                   www.sensiolabs.org
Mapping the Document

                              /** @Document */
                              class User
                              {
                                  /** @Id */
                                  private $id;
                                  /** @String */
                                  private $username;
                                  /** @String */
                                  private $password;

                                      // ...
                              }




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Ready to Go
        Doctrine now knows about this document and is able
                   to manage its persistent state




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Inserting, Updating and
          Deleting Documents


Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Inserting Documents
                   $user = new User();
                   $user->setUsername('jwage');
                   $user->setPassword('changeme');

                   $dm->persist($user);
                   $dm->flush(); // inserts document




                               $users = array(
                                   array(
                                       'username' => 'jwage',
                                       'password' => 'changeme'
                                   )
                               );
                               $coll->batchInsert($users);




Doctrine MongoDB ODM    www.doctrine-project.org        www.sensiolabs.org
Updating Documents
   $user = $dm->findOne('User', array('username' => 'jwage'));

   $user->setUsername('jonwage');
   $user->setPassword('newpassword');

   $dm->flush(); // updates document




                   $coll->update(
                       array('_id' => 'theid'),
                       array('$set' => array(
                           'username' => 'jonwage',
                           'password' => '5e9d11a14ad1c8dd77e98ef9b53fd1ba'
                       )
                   );




Doctrine MongoDB ODM        www.doctrine-project.org   www.sensiolabs.org
Removing Documents

   $user = $dm->findOne('User', array('username' => 'jwage'));

   $dm->remove($user);
   $dm->flush(); // removes document




                       $coll->remove(array('_id' => 'theid'));




Doctrine MongoDB ODM         www.doctrine-project.org   www.sensiolabs.org
Query API
                            Fluent OO Query API




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Querying MongoDB
                  Directly

   // Get user array directly from mongo
   $user = $mongo->db->users->findOne(array('username' => 'jwage'));




                       Returns an array of information and not a User object




Doctrine MongoDB ODM          www.doctrine-project.org   www.sensiolabs.org
Querying Through
                    Doctrine

   // Get user class instance through Doctrine
   $user = $dm->findOne('User', array('username' => 'jwage'));




          Going through Doctrine gives you managed objects back instead of arrays




Doctrine MongoDB ODM       www.doctrine-project.org   www.sensiolabs.org
Querying Through
             Doctrine Query API

   // Get user class instance through Doctrine Query API
   $user = $dm->createQuery('User')
       ->field('username')->equals('jwage')
       ->getSingleResult();




                       Query for same user using the Query API




Doctrine MongoDB ODM    www.doctrine-project.org   www.sensiolabs.org
Querying Through
             Doctrine Query API

              // Find posts within a range of dates
              $posts = $dm->createQuery('Post')
                  ->field('createdAt')->range($startDate, $endDate)
                  ->execute();




Doctrine MongoDB ODM     www.doctrine-project.org   www.sensiolabs.org
Updating Documents

              // Update a document
              $dm->createQuery('User')
                  ->update()
                  ->field('username')->set('jonwage')
                  ->field('password')->set('newpassword')
                  ->field('username')->equals('jwage')
                  ->execute();




Doctrine MongoDB ODM    www.doctrine-project.org   www.sensiolabs.org
Removing Documents

               // Remove a document
               $dm->createQuery('User')
                           // Remove a document
                           $dm->createQuery('User')

                   ->remove()  ->remove()
                               ->field('username')->equals('jwage')
                               ->execute();
                   ->field('username')->equals('jwage')
                   ->execute();




Doctrine MongoDB ODM     www.doctrine-project.org   www.sensiolabs.org
Embedded Documents



Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
class User
                 {
                     /** @Id */
                     public $id;

                       /** @String */
                       public $name;

                       /** @EmbedMany(targetDocument="Address") */
                       public $addresses = array();
                 }




Doctrine MongoDB ODM        www.doctrine-project.org   www.sensiolabs.org
/** @EmbeddedDocument */
                            class Address
                            {
                                /** @String */
                                public $address;

                                    /** @String */
                                    public $city;

                                    /** @String */
                                    public $state;

                                    /** @String */
                                    public $zipcode;
                            }




Doctrine MongoDB ODM   www.doctrine-project.org      www.sensiolabs.org
$user = new User();
             $user->name = 'Jonathan H. Wage';

             $address = new Address();
             $address->address = '6512 Mercomatic Ct';
             $address->city = 'Nashville';
             $address->state = 'Tennessee';
             $address->zipcode = '37209';
             $user->addresses[] = $address;

             $dm->persist($user);
             $dm->flush();




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
$users = array(
                 array(
                     'name' => 'Jonathan H. Wage',
                     'addresses' => array(
                         array(
                             'address' => '6512 Mercomatic Ct',
                             'city' => 'Nashville',
                             'state' => 'Tennesseee',
                             'zipcode' => '37209'
                         )
                     )
                 )
             );
             $coll->batchInsert($users);




Doctrine MongoDB ODM    www.doctrine-project.org   www.sensiolabs.org
Updating Embedded
                Documents
         Uses dot notation and atomic operators for updating




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
$user = $dm->findOne('User', array('name' => 'Jonathan H. Wage'));
             $user->addresses[0]->zipcode = '37205';
             $dm->flush();




             $coll->update(
                 array('_id' => 'theuserid'),
                 array('$set' => array('addresses.0.zipcode' => '37209'))
             );




Doctrine MongoDB ODM       www.doctrine-project.org   www.sensiolabs.org
Add New Address



Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
$user = $dm->findOne('User', array('name' => 'Jonathan H. Wage'));

       $address = new Address();
       $address->address = '475 Buckhead Ave.';
       $address->city = 'Atlanta';
       $address->state = 'Georgia';
       $address->zipcode = '30305';
       $user->addresses[] = $address;

       $dm->flush();




                  $coll->update(
                      array('_id' => 'theuserid'),
                      array('$pushAll' => array(
                          'addresses' => array(
                              array(
                                  'address' => '475 Buckhead Ave.',
                                  'city' => 'Atlanta',
                                  'state' => 'Georgia',
                                  'zipcode' => '30305'
                              )
                          )
                      ))
                  );



Doctrine MongoDB ODM        www.doctrine-project.org   www.sensiolabs.org
unset($user->addresses[0]->zipcode);
       $dm->flush();



                       $coll->update(
                           array('_id' => 'theuserid'),
                           array(
                               '$unset' => array(
                                   'addresses.0.zipcode'                 => 1
                               )
                           )
                       );




Doctrine MongoDB ODM     www.doctrine-project.org   www.sensiolabs.org
References
        MongoDB does not have joins or foreign keys but you
         can still store references to other documents and
          resolve the references in your application code.
        Doctrine abstracts the handling of referneces for you
                  so working with them is seamless.



Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Organization
                       /** @Document */
                       class Organization
                       {
                           /** @Id */
                           private $id;

                            /** @String */
                            private $name;

                            /** @ReferenceMany(targetDocument="User") */
                            private $users = array();

                            public function setName($name)
                            {
                                $this->name = $name;
                            }

                            public function addUser(User $user)
                            {
                                $this->users[] = $user;
                            }
                       }




Doctrine MongoDB ODM       www.doctrine-project.org      www.sensiolabs.org
User
                   /** @Document */
                   class User
                   {
                       /** @Id */
                       private $id;

                       /** @String */
                       private $name;

                       /** @ReferenceOne(targetDocument="Organization") */
                       private $organization;

                       public function setName($name)
                       {
                           $this->name = $name;
                       }

                       public function setOrganization(Organization $organization)
                       {
                           $this->organization = $organization;
                           $organization->addUser($this);
                       }
                   }




Doctrine MongoDB ODM          www.doctrine-project.org        www.sensiolabs.org
$organization = new Organization();
                 $organization->setName('Sensio Labs');

                 $user = new User();
                 $user->setName('Jonathan H. Wage');
                 $user->setOrganization($organization);

                 $dm->persist($organization);
                 $dm->persist($user);
                 $dm->flush();




Doctrine MongoDB ODM     www.doctrine-project.org   www.sensiolabs.org
The Result



Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Array
                   (
                       [_id] => 4c86acd78ead0e8759000000
                       [name] => Sensio Labs
                       [users] => Array
                           (
                               [0] => Array
                                   (
                                        [$ref] => User
                                        [$id] => 4c86acd78ead0e8759010000
                                        [$db] => doctrine_odm_sandbox
                                   )

                           )

                   )


                   Array
                   (
                       [_id] => 4c86acd78ead0e8759010000
                       [name] => Jonathan H. Wage
                       [organization] => Array
                           (
                               [$ref] => Organization
                               [$id] => 4c86acd78ead0e8759000000
                               [$db] => doctrine_odm_sandbox
                           )

                   )




Doctrine MongoDB ODM           www.doctrine-project.org            www.sensiolabs.org
Working with
                        References



Doctrine MongoDB ODM    www.doctrine-project.org   www.sensiolabs.org
$user = $dm->find('User', array('name' => 'Jonathan H. Wage'));

           // instance of uninitialized OrganizationProxy
           $organization = $user->getOrganization();

           // calling getter or setter for uninitialized proxy
           // queries the database and initialized the proxy document

           // query invoked, organization data loaded and doc initialized
           echo $organization->getName();




Doctrine MongoDB ODM      www.doctrine-project.org   www.sensiolabs.org
$organization = $dm->find('Organization', array('name' => 'Sensio Labs'));
     $users = $organization->getUsers(); // uninitialized collection

     // Queries database for users and initializes collection
     foreach ($users as $user)
     {
         // ...
     }




Doctrine MongoDB ODM     www.doctrine-project.org   www.sensiolabs.org
Change Tracking



Doctrine MongoDB ODM     www.doctrine-project.org   www.sensiolabs.org
UnitOfWork
  •    Tracks changes in objects between flushes

  •    Maintains copy of old values to compare
       new values to

  •    Changesets computed and persisted in
       the most efficient way using atomic
       operators $inc, $set, $unset, $pullAll,
       $pushAll, etc.

Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Other Features



Doctrine MongoDB ODM    www.doctrine-project.org   www.sensiolabs.org
Document Query
                    Language
         Language for querying documents in a similar way to
                                SQL




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
BNF Grammar



Doctrine MongoDB ODM    www.doctrine-project.org   www.sensiolabs.org
QueryLanguage ::= FindQuery | InsertQuery | UpdateQuery | RemoveQuery

               FindQuery ::= FindClause [WhereClause] [MapClause] [ReduceClause] [SortClause] [LimitClause]
               [SkipClause]
               FindClause ::= "FIND" all | SelectField {"," SelectField}
               SelectField ::= DocumentFieldName
               SortClause ::= SortClauseField {"," SortClauseField}
               SortClauseField ::= DocumentFieldName "ASC | DESC"
               LimitClause ::= "LIMIT" LimitInteger
               SkipClause ::= "SKIP" SkipInteger
               MapClause ::= "MAP" MapFunction
               ReduceClause ::= "REDUCE" ReduceFunction

               DocumentFieldName ::= DocumentFieldName | EmbeddedDocument "." {"." DocumentFieldName}
               WhereClause ::= "WHERE" WhereClausePart {"AND" WhereClausePart}
               WhereClausePart ::= ["all", "not"] DocumentFieldName WhereClauseExpression Value
               WhereClauseExpression ::= "=" | "!=" | ">=" | "<=" | ">" | "<" | "in"
                                       "notIn" | "all" | "size" | "exists" | "type"
               Value ::= LiteralValue | JsonObject | JsonArray

               UpdateQuery ::= UpdateClause [WhereClause]
               UpdateClause ::= [SetExpression], [UnsetExpression], [IncrementExpression],
                                 [PushExpression], [PushAllExpression], [PullExpression],
                                 [PullAllExpression], [AddToSetExpression], [AddManyToSetExpression],
                                 [PopFirstExpression], [PopLastExpression]
               SetExpression ::= "SET" DocumentFieldName "=" Value {"," SetExpression}
               UnsetExpression ::= "UNSET" DocumentFieldName {"," UnsetExpression}
               IncrementExpression ::= "INC" DocumentFieldName "=" IncrementInteger {"," IncrementExpression}
               PushExpression ::= "PUSH" DocumentFieldName Value {"," PushExpression}
               PushAllExpression ::= "PUSHALL" DocumentFieldName Value {"," PushAllExpression}
               PullExpression ::= "PULL" DocumentFieldName Value {"," PullExpression}
               PullAllExpression ::= "PULLALL" DocumentFieldName Value {"," PullAllExpression}
               AddToSetExpression ::= "ADDTOSET" DocumentFieldName Value {"," AddToSetExpression}
               AddManyToSetExpression ::= "ADDMANYTOSET" DocumentFieldName Value {"," AddManyToSetExpression}
               PopFirstExpression ::= "POPFIRST" DocumentFieldName {"," PopFirstExpression}
               PopLastExpression ::= "POPLAST" DocumentFieldName {"," PopLastExpression}

               InsertQuery ::= InsertClause InsertSetClause {"," InsertSetClause}
               InsertSetClause ::= DocumentFieldName "=" Value

               RemoveQuery ::= RemoveClause [WhereClause]




Doctrine MongoDB ODM              www.doctrine-project.org                  www.sensiolabs.org
Creating Query


                $users = $dm->query('find all FROM User');




Doctrine MongoDB ODM    www.doctrine-project.org   www.sensiolabs.org
Selecting Fields


            $users = $dm->query('find username FROM User');




Doctrine MongoDB ODM     www.doctrine-project.org   www.sensiolabs.org
Paging Results


       $users = $dm->query('find all FROM User limit 30 skip 30');




Doctrine MongoDB ODM    www.doctrine-project.org   www.sensiolabs.org
Selecting Slice of
         Embedded Documents

  $post = $dm->query('find title, comments limit 20 skip 10 FROM
  BlogPost WHERE id = ?', array($id));




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Other Examples
// Find all posts greater than or equal to a date
$posts = $dm->query('find all FROM BlogPost WHERE createdAt >= ?',
array($date));

// Find all posts sorted by created at desc
$posts = $dm->query('find all FROM BlogPost sort createdAt desc');

// Update user
$dm->query('update DocumentsUser set password = ? where username = ?',
array('newpassword', 'jwage'));




Doctrine MongoDB ODM     www.doctrine-project.org   www.sensiolabs.org
Lifecycle Events



Doctrine MongoDB ODM     www.doctrine-project.org   www.sensiolabs.org
“A lifecycle event is a regular event with the additional
    feature of providing a mechanism to register direct
   callbacks inside the corresponding document classes
    that are executed when the lifecycle event occurs.”


   http://www.doctrine-project.org/projects/mongodb_odm/1.0/docs/reference/events/en#lifecycle-callbacks




Doctrine MongoDB ODM           www.doctrine-project.org       www.sensiolabs.org
•    preRemove - The preRemove event occurs for a given document before the
     respective DocumentManager remove operation for that document is
     executed.
•    postRemove - The postRemove event occurs for an document after the
     document has been removed. It will be invoked after the database delete
     operations.
•    prePersist - The prePersist event occurs for a given document before the
     respective DocumentManager persist operation for that document is executed.
•    postPersist - The postPersist event occurs for an document after the
     document has been made persistent. It will be invoked after the database insert
     operations. Generated primary key values are available in the postPersist event.
•    preUpdate - The preUpdate event occurs before the database update
     operations to document data.
•    postUpdate - The postUpdate event occurs after the database update
     operations to document data.
•    postLoad - The postLoad event occurs for an document after the document
     has been loaded into the current DocumentManager from the database or after
     the refresh operation has been applied to it.

    Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
Event Examples



Doctrine MongoDB ODM    www.doctrine-project.org   www.sensiolabs.org
/**
                         * @Document
                         * @HasLifecycleCallbacks
                         */
                       class BlogPost
                       {
                            /** @Id */
                            public $id;
                            /** @Date */
                            public $createdAt;
                            /** @Date */
                            public $updatedAt;

                           /** @PreUpdate */
                           public function prePersist()
                           {
                               $this->createdAt = new DateTime();
                           }

                           /** @PreUpdate */
                           public function preUpdate()
                           {
                               $this->updatedAt = new DateTime();
                           }
                       }




Doctrine MongoDB ODM       www.doctrine-project.org      www.sensiolabs.org
Migrating Data



Doctrine MongoDB ODM    www.doctrine-project.org   www.sensiolabs.org
Initial Document
                       /**
                         * @Document
                         */
                       class User
                       {
                            /** @Id */
                            public $id;
                            /** @String */
                            public $name;
                       }




Doctrine MongoDB ODM   www.doctrine-project.org   www.sensiolabs.org
New Document
                        /**
                          * @Document
                          */
                        class User
                        {
                             /** @Id */
                             public $id;
                             /** @String */
                             public $firstName;
                             /** @String */
                             public $lastName;
                        }




Doctrine MongoDB ODM     www.doctrine-project.org   www.sensiolabs.org
Migrate Documents
          With Old Field Name
                       /**
                         * @Document
                         * @HasLifecycleCallbacks
                         */
                       class User
                       {
                            /** @Id */
                            public $id;
                            /** @String */
                            public $firstName;
                            /** @String */
                            public $lastName;

                           /** @PreLoad */
                           public function preLoad(array &$data)
                           {
                               if (isset($data['name']))
                               {
                                   $e = explode(' ', $data['name']);
                                   unset($data['name']);
                                   $data['firstName'] = $e[0];
                                   $data['lastName'] = $e[1];
                               }
                           }




Doctrine MongoDB ODM      www.doctrine-project.org           www.sensiolabs.org
Questions?
                         Jonathan H. Wage
                  •    http://www.twitter.com/jwage

                  •    http://www.jwage.com

                  •    http://www.facebook.com/jwage

              You can contact Jonathan about Doctrine and Open-Source or for
              training, consulting, application development, or business related
                           questions at jonathan.wage@sensio.com




Doctrine MongoDB ODM       www.doctrine-project.org   www.sensiolabs.org

More Related Content

What's hot

JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional StatementsMarlon Jamera
 
Regular Expressions in PHP
Regular Expressions in PHPRegular Expressions in PHP
Regular Expressions in PHPAndrew Kandels
 
Media Art II 2013 第7回 : openFrameworks 3Dグラフィクス、OpenGL
Media Art II 2013 第7回 : openFrameworks 3Dグラフィクス、OpenGLMedia Art II 2013 第7回 : openFrameworks 3Dグラフィクス、OpenGL
Media Art II 2013 第7回 : openFrameworks 3Dグラフィクス、OpenGLAtsushi Tadokoro
 
[0602 박민근] Direct2D
[0602 박민근] Direct2D[0602 박민근] Direct2D
[0602 박민근] Direct2D흥배 최
 
C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2Chris Ohk
 
HTML + CSS Examples
HTML + CSS ExamplesHTML + CSS Examples
HTML + CSS ExamplesMohamed Loey
 
MacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) ExploitationMacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) ExploitationAngel Boy
 
ROP 輕鬆談
ROP 輕鬆談ROP 輕鬆談
ROP 輕鬆談hackstuff
 
An introduction to SQLAlchemy
An introduction to SQLAlchemyAn introduction to SQLAlchemy
An introduction to SQLAlchemymengukagan
 
Cursuri. Calculatoare de bord.pdf
Cursuri. Calculatoare de bord.pdfCursuri. Calculatoare de bord.pdf
Cursuri. Calculatoare de bord.pdfChristinaArgesanu
 
OptView2 - C++ on Sea 2022
OptView2 - C++ on Sea 2022OptView2 - C++ on Sea 2022
OptView2 - C++ on Sea 2022Ofek Shilon
 
C++ 미정의 행동(undefined behavior)
C++ 미정의 행동(undefined behavior)C++ 미정의 행동(undefined behavior)
C++ 미정의 행동(undefined behavior)은아 정
 
HTML Semantic Tags
HTML Semantic TagsHTML Semantic Tags
HTML Semantic TagsBruce Kyle
 
Prototype programming in JavaScript
Prototype programming in JavaScriptPrototype programming in JavaScript
Prototype programming in JavaScriptTimur Shemsedinov
 
Introduction to SQL Antipatterns
Introduction to SQL AntipatternsIntroduction to SQL Antipatterns
Introduction to SQL AntipatternsKrishnakumar S
 

What's hot (20)

JavaScript Conditional Statements
JavaScript Conditional StatementsJavaScript Conditional Statements
JavaScript Conditional Statements
 
Regular Expressions in PHP
Regular Expressions in PHPRegular Expressions in PHP
Regular Expressions in PHP
 
Media Art II 2013 第7回 : openFrameworks 3Dグラフィクス、OpenGL
Media Art II 2013 第7回 : openFrameworks 3Dグラフィクス、OpenGLMedia Art II 2013 第7回 : openFrameworks 3Dグラフィクス、OpenGL
Media Art II 2013 第7回 : openFrameworks 3Dグラフィクス、OpenGL
 
[0602 박민근] Direct2D
[0602 박민근] Direct2D[0602 박민근] Direct2D
[0602 박민근] Direct2D
 
WebGL 2.0 Reference Guide
WebGL 2.0 Reference GuideWebGL 2.0 Reference Guide
WebGL 2.0 Reference Guide
 
Php cookies
Php cookiesPhp cookies
Php cookies
 
C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2C++17 Key Features Summary - Ver 2
C++17 Key Features Summary - Ver 2
 
HTML + CSS Examples
HTML + CSS ExamplesHTML + CSS Examples
HTML + CSS Examples
 
Inheritance
InheritanceInheritance
Inheritance
 
MacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) ExploitationMacOS memory allocator (libmalloc) Exploitation
MacOS memory allocator (libmalloc) Exploitation
 
ROP 輕鬆談
ROP 輕鬆談ROP 輕鬆談
ROP 輕鬆談
 
Лекция 4. Принципы SOLID
Лекция 4. Принципы SOLID Лекция 4. Принципы SOLID
Лекция 4. Принципы SOLID
 
Control Structures In Php 2
Control Structures In Php 2Control Structures In Php 2
Control Structures In Php 2
 
An introduction to SQLAlchemy
An introduction to SQLAlchemyAn introduction to SQLAlchemy
An introduction to SQLAlchemy
 
Cursuri. Calculatoare de bord.pdf
Cursuri. Calculatoare de bord.pdfCursuri. Calculatoare de bord.pdf
Cursuri. Calculatoare de bord.pdf
 
OptView2 - C++ on Sea 2022
OptView2 - C++ on Sea 2022OptView2 - C++ on Sea 2022
OptView2 - C++ on Sea 2022
 
C++ 미정의 행동(undefined behavior)
C++ 미정의 행동(undefined behavior)C++ 미정의 행동(undefined behavior)
C++ 미정의 행동(undefined behavior)
 
HTML Semantic Tags
HTML Semantic TagsHTML Semantic Tags
HTML Semantic Tags
 
Prototype programming in JavaScript
Prototype programming in JavaScriptPrototype programming in JavaScript
Prototype programming in JavaScript
 
Introduction to SQL Antipatterns
Introduction to SQL AntipatternsIntroduction to SQL Antipatterns
Introduction to SQL Antipatterns
 

Viewers also liked

Hands on Big Data Analysis with MongoDB - Cloud Expo Bootcamp NYC
Hands on Big Data Analysis with MongoDB - Cloud Expo Bootcamp NYCHands on Big Data Analysis with MongoDB - Cloud Expo Bootcamp NYC
Hands on Big Data Analysis with MongoDB - Cloud Expo Bootcamp NYCLaura Ventura
 
Beginner's guide to Mongodb and NoSQL
Beginner's guide to Mongodb and NoSQL  Beginner's guide to Mongodb and NoSQL
Beginner's guide to Mongodb and NoSQL Maulin Shah
 
Mongo db crud guide
Mongo db crud guideMongo db crud guide
Mongo db crud guideDeysi Gmarra
 
Data Migration Between MongoDB and Oracle
Data Migration Between MongoDB and OracleData Migration Between MongoDB and Oracle
Data Migration Between MongoDB and OracleChihYung(Raymond) Wu
 
Effective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 DevelopersEffective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 DevelopersMarcin Chwedziak
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialSteven Francia
 
MongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and ImplicationsMongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and ImplicationsMongoDB
 
MongoDB, E-commerce and Transactions
MongoDB, E-commerce and TransactionsMongoDB, E-commerce and Transactions
MongoDB, E-commerce and TransactionsSteven Francia
 

Viewers also liked (12)

Mongo db manual
Mongo db manualMongo db manual
Mongo db manual
 
Hands on Big Data Analysis with MongoDB - Cloud Expo Bootcamp NYC
Hands on Big Data Analysis with MongoDB - Cloud Expo Bootcamp NYCHands on Big Data Analysis with MongoDB - Cloud Expo Bootcamp NYC
Hands on Big Data Analysis with MongoDB - Cloud Expo Bootcamp NYC
 
MongoDB DOC v1.5
MongoDB DOC v1.5MongoDB DOC v1.5
MongoDB DOC v1.5
 
Beginner's guide to Mongodb and NoSQL
Beginner's guide to Mongodb and NoSQL  Beginner's guide to Mongodb and NoSQL
Beginner's guide to Mongodb and NoSQL
 
Mongo db crud guide
Mongo db crud guideMongo db crud guide
Mongo db crud guide
 
MONGODB
MONGODBMONGODB
MONGODB
 
Data Migration Between MongoDB and Oracle
Data Migration Between MongoDB and OracleData Migration Between MongoDB and Oracle
Data Migration Between MongoDB and Oracle
 
Effective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 DevelopersEffective Doctrine2: Performance Tips for Symfony2 Developers
Effective Doctrine2: Performance Tips for Symfony2 Developers
 
OSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB TutorialOSCON 2012 MongoDB Tutorial
OSCON 2012 MongoDB Tutorial
 
API Gateway report
API Gateway reportAPI Gateway report
API Gateway report
 
MongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and ImplicationsMongoDB Schema Design: Practical Applications and Implications
MongoDB Schema Design: Practical Applications and Implications
 
MongoDB, E-commerce and Transactions
MongoDB, E-commerce and TransactionsMongoDB, E-commerce and Transactions
MongoDB, E-commerce and Transactions
 

Similar to Doctrine MongoDB Object Document Mapper

Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMJonathan Wage
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2zfconfua
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony AppsKris Wallsmith
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency InjectionRifat Nabi
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQLddiers
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For BeginnersJonathan Wage
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationJonathan Wage
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistenceHugo Hamon
 
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Fabien Potencier
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8Alexei Gorobets
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7chuvainc
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Editionddiers
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDBFitz Agard
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)MongoSF
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the TrenchesJonathan Wage
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Oliver Gierke
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 

Similar to Doctrine MongoDB Object Document Mapper (20)

Symfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODMSymfony Day 2010 Doctrine MongoDB ODM
Symfony Day 2010 Doctrine MongoDB ODM
 
Doctrine 2
Doctrine 2Doctrine 2
Doctrine 2
 
How Kris Writes Symfony Apps
How Kris Writes Symfony AppsHow Kris Writes Symfony Apps
How Kris Writes Symfony Apps
 
Dependency Injection
Dependency InjectionDependency Injection
Dependency Injection
 
Doctrine and NoSQL
Doctrine and NoSQLDoctrine and NoSQL
Doctrine and NoSQL
 
Doctrine for NoSQL
Doctrine for NoSQLDoctrine for NoSQL
Doctrine for NoSQL
 
Drupal II: The SQL
Drupal II: The SQLDrupal II: The SQL
Drupal II: The SQL
 
Doctrine For Beginners
Doctrine For BeginnersDoctrine For Beginners
Doctrine For Beginners
 
Symfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 IntegrationSymfony2 and Doctrine2 Integration
Symfony2 and Doctrine2 Integration
 
The History of PHPersistence
The History of PHPersistenceThe History of PHPersistence
The History of PHPersistence
 
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
Decouple Your Code For Reusability (International PHP Conference / IPC 2008)
 
Dependency injection in Drupal 8
Dependency injection in Drupal 8Dependency injection in Drupal 8
Dependency injection in Drupal 8
 
DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7DrupalCamp Foz - Novas APIs Drupal 7
DrupalCamp Foz - Novas APIs Drupal 7
 
Drupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary EditionDrupal - dbtng 25th Anniversary Edition
Drupal - dbtng 25th Anniversary Edition
 
Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09Spl Not A Bridge Too Far phpNW09
Spl Not A Bridge Too Far phpNW09
 
PHP Development With MongoDB
PHP Development With MongoDBPHP Development With MongoDB
PHP Development With MongoDB
 
PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)PHP Development with MongoDB (Fitz Agard)
PHP Development with MongoDB (Fitz Agard)
 
Symfony2 from the Trenches
Symfony2 from the TrenchesSymfony2 from the Trenches
Symfony2 from the Trenches
 
Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!Data access 2.0? Please welcome: Spring Data!
Data access 2.0? Please welcome: Spring Data!
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 

More from Jonathan Wage

OpenSky Infrastructure
OpenSky InfrastructureOpenSky Infrastructure
OpenSky InfrastructureJonathan Wage
 
Doctrine In The Real World sflive2011 Paris
Doctrine In The Real World sflive2011 ParisDoctrine In The Real World sflive2011 Paris
Doctrine In The Real World sflive2011 ParisJonathan Wage
 
Doctrine in the Real World
Doctrine in the Real WorldDoctrine in the Real World
Doctrine in the Real WorldJonathan Wage
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMJonathan Wage
 
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectJonathan Wage
 
Doctrine 2 - Enterprise Persistence Layer For PHP
Doctrine 2 - Enterprise Persistence Layer For PHPDoctrine 2 - Enterprise Persistence Layer For PHP
Doctrine 2 - Enterprise Persistence Layer For PHPJonathan Wage
 
Introduction To Doctrine 2
Introduction To Doctrine 2Introduction To Doctrine 2
Introduction To Doctrine 2Jonathan Wage
 
Doctrine 2 - Not The Same Old Php Orm
Doctrine 2 - Not The Same Old Php OrmDoctrine 2 - Not The Same Old Php Orm
Doctrine 2 - Not The Same Old Php OrmJonathan Wage
 
Doctrine 2: Enterprise Persistence Layer for PHP
Doctrine 2: Enterprise Persistence Layer for PHPDoctrine 2: Enterprise Persistence Layer for PHP
Doctrine 2: Enterprise Persistence Layer for PHPJonathan Wage
 
Sympal A Cmf Based On Symfony
Sympal   A Cmf Based On SymfonySympal   A Cmf Based On Symfony
Sympal A Cmf Based On SymfonyJonathan Wage
 
Symfony 1.3 + Doctrine 1.2
Symfony 1.3 + Doctrine 1.2Symfony 1.3 + Doctrine 1.2
Symfony 1.3 + Doctrine 1.2Jonathan Wage
 
Sympal - The flexible Symfony CMS
Sympal - The flexible Symfony CMSSympal - The flexible Symfony CMS
Sympal - The flexible Symfony CMSJonathan Wage
 
What's new in Doctrine
What's new in DoctrineWhat's new in Doctrine
What's new in DoctrineJonathan Wage
 
Sympal - Symfony CMS Preview
Sympal - Symfony CMS PreviewSympal - Symfony CMS Preview
Sympal - Symfony CMS PreviewJonathan Wage
 
Doctrine Php Object Relational Mapper
Doctrine Php Object Relational MapperDoctrine Php Object Relational Mapper
Doctrine Php Object Relational MapperJonathan Wage
 
Sympal - The Flexible Symfony Cms
Sympal - The Flexible Symfony CmsSympal - The Flexible Symfony Cms
Sympal - The Flexible Symfony CmsJonathan Wage
 
What's New In Doctrine
What's New In DoctrineWhat's New In Doctrine
What's New In DoctrineJonathan Wage
 

More from Jonathan Wage (19)

OpenSky Infrastructure
OpenSky InfrastructureOpenSky Infrastructure
OpenSky Infrastructure
 
Doctrine In The Real World sflive2011 Paris
Doctrine In The Real World sflive2011 ParisDoctrine In The Real World sflive2011 Paris
Doctrine In The Real World sflive2011 Paris
 
Doctrine in the Real World
Doctrine in the Real WorldDoctrine in the Real World
Doctrine in the Real World
 
ZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODMZendCon2010 Doctrine MongoDB ODM
ZendCon2010 Doctrine MongoDB ODM
 
ZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine ProjectZendCon2010 The Doctrine Project
ZendCon2010 The Doctrine Project
 
Libertyvasion2010
Libertyvasion2010Libertyvasion2010
Libertyvasion2010
 
Doctrine 2 - Enterprise Persistence Layer For PHP
Doctrine 2 - Enterprise Persistence Layer For PHPDoctrine 2 - Enterprise Persistence Layer For PHP
Doctrine 2 - Enterprise Persistence Layer For PHP
 
Introduction To Doctrine 2
Introduction To Doctrine 2Introduction To Doctrine 2
Introduction To Doctrine 2
 
Doctrine 2 - Not The Same Old Php Orm
Doctrine 2 - Not The Same Old Php OrmDoctrine 2 - Not The Same Old Php Orm
Doctrine 2 - Not The Same Old Php Orm
 
Doctrine 2: Enterprise Persistence Layer for PHP
Doctrine 2: Enterprise Persistence Layer for PHPDoctrine 2: Enterprise Persistence Layer for PHP
Doctrine 2: Enterprise Persistence Layer for PHP
 
Sympal A Cmf Based On Symfony
Sympal   A Cmf Based On SymfonySympal   A Cmf Based On Symfony
Sympal A Cmf Based On Symfony
 
Symfony 1.3 + Doctrine 1.2
Symfony 1.3 + Doctrine 1.2Symfony 1.3 + Doctrine 1.2
Symfony 1.3 + Doctrine 1.2
 
Sympal - The flexible Symfony CMS
Sympal - The flexible Symfony CMSSympal - The flexible Symfony CMS
Sympal - The flexible Symfony CMS
 
What's new in Doctrine
What's new in DoctrineWhat's new in Doctrine
What's new in Doctrine
 
What Is Doctrine?
What Is Doctrine?What Is Doctrine?
What Is Doctrine?
 
Sympal - Symfony CMS Preview
Sympal - Symfony CMS PreviewSympal - Symfony CMS Preview
Sympal - Symfony CMS Preview
 
Doctrine Php Object Relational Mapper
Doctrine Php Object Relational MapperDoctrine Php Object Relational Mapper
Doctrine Php Object Relational Mapper
 
Sympal - The Flexible Symfony Cms
Sympal - The Flexible Symfony CmsSympal - The Flexible Symfony Cms
Sympal - The Flexible Symfony Cms
 
What's New In Doctrine
What's New In DoctrineWhat's New In Doctrine
What's New In Doctrine
 

Recently uploaded

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
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
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...shyamraj55
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxnull - The Open Security Community
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024BookNet Canada
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsPrecisely
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 

Recently uploaded (20)

FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
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
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
DMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special EditionDMCC Future of Trade Web3 - Special Edition
DMCC Future of Trade Web3 - Special Edition
 
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
Automating Business Process via MuleSoft Composer | Bangalore MuleSoft Meetup...
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptxMaking_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
Making_way_through_DLL_hollowing_inspite_of_CFG_by_Debjeet Banerjee.pptx
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC BiblioShare - Tech Forum 2024
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptxVulnerability_Management_GRC_by Sohang Sengupta.pptx
Vulnerability_Management_GRC_by Sohang Sengupta.pptx
 
Unlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power SystemsUnlocking the Potential of the Cloud for IBM Power Systems
Unlocking the Potential of the Cloud for IBM Power Systems
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 

Doctrine MongoDB Object Document Mapper

  • 1. Doctrine MongoDB Object Document Mapper (ODM) Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 2. What is Doctrine? Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 3. What is Doctrine? • Open source PHP project started in 2006 • Relational database abstraction layer. • mysql, oracle, pgsql, sqlite, etc. • Object persistence layers for RDBMS, MongoDB, etc. • Other database related functionalities. http://www.doctrine-project.org Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 4. What is MongoDB? • Key-Value document based storage system. • Bridge between traditional relational databases and key-value data stores. http://www.mongodb.org Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 5. Terminology RDBMS MongoDB Database Database Table Collection Row Document Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 6. Using MongoDB in PHP Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 7. Connecting $mongo = new Mongo('mongodb://localhost'); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 8. Selecting Databases $mongo = new Mongo('mongodb://localhost'); $db = $mongo->selectDB('dbname'); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 9. Selecting Collections $mongo = new Mongo('mongodb://localhost'); $db = $mongo->selectDB('dbname'); $coll = $db->selectCollection('users'); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 10. Inserting Documents Insert a new user document and echo the newly generated id $user = array( 'username' => 'jwage', 'password' => md5('changeme') 'active' => true ); $coll->insert($user); echo $user['_id']; Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 11. Updating Documents Update username and password and save the whole document $user = $coll->findOne(array('username' => 'jwage')); $user['username'] = 'jonwage'; $user['password'] = md5('newpassword'); $coll->save($user); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 12. Atomic Updates • Faster than saving the entire document. • Safer than updating the entire document. • Updates are done in place and are atomic. Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 13. Atomic Updates Update username and password where username is jwage $coll->update(array( 'username' => 'jwage' ), array( '$set' => array( 'username' => 'jonwage', 'password' => md5('newpassword') ) )); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 14. Atomic Updates Many other atomic operators exist for manipulating a documents data • $inc - increments field by the number value • $set - sets field to value • $unset - deletes a given field • $push - appends value to an array • $pushAll - appends multiple values to an array • $addToSet - appends multiple values to an array that don’t already exist in the array • $pop - removes the last element in an array • $pull - removes all occurrences of a value from an array • $pullAll - removes all occurrences of multiple values from an array Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 15. Removing Documents $coll->remove(array('username' => 'jwage')); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 16. Doctrine + MongoDB Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 17. DocumentManager • Abstraction on top of the PHP Mongo class • Manages the persistent state of PHP objects • Implements UnitOfWork for change tracking http://martinfowler.com/eaaCatalog/unitOfWork.html Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 18. Document States • A NEW document instance has no persistent identity, and is not yet associated with a DocumentManager (i.e. those just created with the "new" operator). • A MANAGED document instance is an instance with a persistent identity that is associated with an DocumentManager and whose persistence is thus managed. • A DETACHED document instance is an instance with a persistent identity that is not (or no longer) associated with an DocumentManager. • A REMOVED document instance is an instance with a persistent identity, associated with an DocumentManager, that will be removed from the database upon transaction commit. Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 19. DocumentManager Create your DocumentManager instance for managing object persistence $config = new DoctrineODMMongoDBConfiguration(); $config->setMetadataCacheImpl(new DoctrineCommonCacheArrayCache); $driverImpl = $config->newDefaultAnnotationDriver(array(__DIR__."/Documents")); $config->setMetadataDriverImpl($driverImpl); $config->setProxyDir(__DIR__ . '/Proxies'); $config->setProxyNamespace('Proxies'); $dm = DoctrineORMDocumentManager::create($mongo, $config); Wraps around existing $mongo connection Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 20. Defining Document A document is just a regular ole’ PHP class class User { private $id; private $username; private $password; public function getId() { return $this->id; } public function getUsername() { return $this->username; } public function setUsername($username) { $this->username = $username; } public function getPassword() { return $this->password; } public function setPassword($password) { $this->password = md5($password); } } Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 21. Mapping the Document /** @Document */ class User { /** @Id */ private $id; /** @String */ private $username; /** @String */ private $password; // ... } Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 22. Ready to Go Doctrine now knows about this document and is able to manage its persistent state Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 23. Inserting, Updating and Deleting Documents Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 24. Inserting Documents $user = new User(); $user->setUsername('jwage'); $user->setPassword('changeme'); $dm->persist($user); $dm->flush(); // inserts document $users = array( array( 'username' => 'jwage', 'password' => 'changeme' ) ); $coll->batchInsert($users); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 25. Updating Documents $user = $dm->findOne('User', array('username' => 'jwage')); $user->setUsername('jonwage'); $user->setPassword('newpassword'); $dm->flush(); // updates document $coll->update( array('_id' => 'theid'), array('$set' => array( 'username' => 'jonwage', 'password' => '5e9d11a14ad1c8dd77e98ef9b53fd1ba' ) ); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 26. Removing Documents $user = $dm->findOne('User', array('username' => 'jwage')); $dm->remove($user); $dm->flush(); // removes document $coll->remove(array('_id' => 'theid')); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 27. Query API Fluent OO Query API Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 28. Querying MongoDB Directly // Get user array directly from mongo $user = $mongo->db->users->findOne(array('username' => 'jwage')); Returns an array of information and not a User object Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 29. Querying Through Doctrine // Get user class instance through Doctrine $user = $dm->findOne('User', array('username' => 'jwage')); Going through Doctrine gives you managed objects back instead of arrays Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 30. Querying Through Doctrine Query API // Get user class instance through Doctrine Query API $user = $dm->createQuery('User') ->field('username')->equals('jwage') ->getSingleResult(); Query for same user using the Query API Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 31. Querying Through Doctrine Query API // Find posts within a range of dates $posts = $dm->createQuery('Post') ->field('createdAt')->range($startDate, $endDate) ->execute(); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 32. Updating Documents // Update a document $dm->createQuery('User') ->update() ->field('username')->set('jonwage') ->field('password')->set('newpassword') ->field('username')->equals('jwage') ->execute(); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 33. Removing Documents // Remove a document $dm->createQuery('User') // Remove a document $dm->createQuery('User') ->remove() ->remove() ->field('username')->equals('jwage') ->execute(); ->field('username')->equals('jwage') ->execute(); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 34. Embedded Documents Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 35. class User { /** @Id */ public $id; /** @String */ public $name; /** @EmbedMany(targetDocument="Address") */ public $addresses = array(); } Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 36. /** @EmbeddedDocument */ class Address { /** @String */ public $address; /** @String */ public $city; /** @String */ public $state; /** @String */ public $zipcode; } Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 37. $user = new User(); $user->name = 'Jonathan H. Wage'; $address = new Address(); $address->address = '6512 Mercomatic Ct'; $address->city = 'Nashville'; $address->state = 'Tennessee'; $address->zipcode = '37209'; $user->addresses[] = $address; $dm->persist($user); $dm->flush(); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 38. $users = array( array( 'name' => 'Jonathan H. Wage', 'addresses' => array( array( 'address' => '6512 Mercomatic Ct', 'city' => 'Nashville', 'state' => 'Tennesseee', 'zipcode' => '37209' ) ) ) ); $coll->batchInsert($users); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 39. Updating Embedded Documents Uses dot notation and atomic operators for updating Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 40. $user = $dm->findOne('User', array('name' => 'Jonathan H. Wage')); $user->addresses[0]->zipcode = '37205'; $dm->flush(); $coll->update( array('_id' => 'theuserid'), array('$set' => array('addresses.0.zipcode' => '37209')) ); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 41. Add New Address Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 42. $user = $dm->findOne('User', array('name' => 'Jonathan H. Wage')); $address = new Address(); $address->address = '475 Buckhead Ave.'; $address->city = 'Atlanta'; $address->state = 'Georgia'; $address->zipcode = '30305'; $user->addresses[] = $address; $dm->flush(); $coll->update( array('_id' => 'theuserid'), array('$pushAll' => array( 'addresses' => array( array( 'address' => '475 Buckhead Ave.', 'city' => 'Atlanta', 'state' => 'Georgia', 'zipcode' => '30305' ) ) )) ); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 43. unset($user->addresses[0]->zipcode); $dm->flush(); $coll->update( array('_id' => 'theuserid'), array( '$unset' => array( 'addresses.0.zipcode' => 1 ) ) ); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 44. References MongoDB does not have joins or foreign keys but you can still store references to other documents and resolve the references in your application code. Doctrine abstracts the handling of referneces for you so working with them is seamless. Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 45. Organization /** @Document */ class Organization { /** @Id */ private $id; /** @String */ private $name; /** @ReferenceMany(targetDocument="User") */ private $users = array(); public function setName($name) { $this->name = $name; } public function addUser(User $user) { $this->users[] = $user; } } Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 46. User /** @Document */ class User { /** @Id */ private $id; /** @String */ private $name; /** @ReferenceOne(targetDocument="Organization") */ private $organization; public function setName($name) { $this->name = $name; } public function setOrganization(Organization $organization) { $this->organization = $organization; $organization->addUser($this); } } Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 47. $organization = new Organization(); $organization->setName('Sensio Labs'); $user = new User(); $user->setName('Jonathan H. Wage'); $user->setOrganization($organization); $dm->persist($organization); $dm->persist($user); $dm->flush(); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 48. The Result Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 49. Array ( [_id] => 4c86acd78ead0e8759000000 [name] => Sensio Labs [users] => Array ( [0] => Array ( [$ref] => User [$id] => 4c86acd78ead0e8759010000 [$db] => doctrine_odm_sandbox ) ) ) Array ( [_id] => 4c86acd78ead0e8759010000 [name] => Jonathan H. Wage [organization] => Array ( [$ref] => Organization [$id] => 4c86acd78ead0e8759000000 [$db] => doctrine_odm_sandbox ) ) Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 50. Working with References Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 51. $user = $dm->find('User', array('name' => 'Jonathan H. Wage')); // instance of uninitialized OrganizationProxy $organization = $user->getOrganization(); // calling getter or setter for uninitialized proxy // queries the database and initialized the proxy document // query invoked, organization data loaded and doc initialized echo $organization->getName(); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 52. $organization = $dm->find('Organization', array('name' => 'Sensio Labs')); $users = $organization->getUsers(); // uninitialized collection // Queries database for users and initializes collection foreach ($users as $user) { // ... } Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 53. Change Tracking Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 54. UnitOfWork • Tracks changes in objects between flushes • Maintains copy of old values to compare new values to • Changesets computed and persisted in the most efficient way using atomic operators $inc, $set, $unset, $pullAll, $pushAll, etc. Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 55. Other Features Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 56. Document Query Language Language for querying documents in a similar way to SQL Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 57. BNF Grammar Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 58. QueryLanguage ::= FindQuery | InsertQuery | UpdateQuery | RemoveQuery FindQuery ::= FindClause [WhereClause] [MapClause] [ReduceClause] [SortClause] [LimitClause] [SkipClause] FindClause ::= "FIND" all | SelectField {"," SelectField} SelectField ::= DocumentFieldName SortClause ::= SortClauseField {"," SortClauseField} SortClauseField ::= DocumentFieldName "ASC | DESC" LimitClause ::= "LIMIT" LimitInteger SkipClause ::= "SKIP" SkipInteger MapClause ::= "MAP" MapFunction ReduceClause ::= "REDUCE" ReduceFunction DocumentFieldName ::= DocumentFieldName | EmbeddedDocument "." {"." DocumentFieldName} WhereClause ::= "WHERE" WhereClausePart {"AND" WhereClausePart} WhereClausePart ::= ["all", "not"] DocumentFieldName WhereClauseExpression Value WhereClauseExpression ::= "=" | "!=" | ">=" | "<=" | ">" | "<" | "in" "notIn" | "all" | "size" | "exists" | "type" Value ::= LiteralValue | JsonObject | JsonArray UpdateQuery ::= UpdateClause [WhereClause] UpdateClause ::= [SetExpression], [UnsetExpression], [IncrementExpression], [PushExpression], [PushAllExpression], [PullExpression], [PullAllExpression], [AddToSetExpression], [AddManyToSetExpression], [PopFirstExpression], [PopLastExpression] SetExpression ::= "SET" DocumentFieldName "=" Value {"," SetExpression} UnsetExpression ::= "UNSET" DocumentFieldName {"," UnsetExpression} IncrementExpression ::= "INC" DocumentFieldName "=" IncrementInteger {"," IncrementExpression} PushExpression ::= "PUSH" DocumentFieldName Value {"," PushExpression} PushAllExpression ::= "PUSHALL" DocumentFieldName Value {"," PushAllExpression} PullExpression ::= "PULL" DocumentFieldName Value {"," PullExpression} PullAllExpression ::= "PULLALL" DocumentFieldName Value {"," PullAllExpression} AddToSetExpression ::= "ADDTOSET" DocumentFieldName Value {"," AddToSetExpression} AddManyToSetExpression ::= "ADDMANYTOSET" DocumentFieldName Value {"," AddManyToSetExpression} PopFirstExpression ::= "POPFIRST" DocumentFieldName {"," PopFirstExpression} PopLastExpression ::= "POPLAST" DocumentFieldName {"," PopLastExpression} InsertQuery ::= InsertClause InsertSetClause {"," InsertSetClause} InsertSetClause ::= DocumentFieldName "=" Value RemoveQuery ::= RemoveClause [WhereClause] Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 59. Creating Query $users = $dm->query('find all FROM User'); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 60. Selecting Fields $users = $dm->query('find username FROM User'); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 61. Paging Results $users = $dm->query('find all FROM User limit 30 skip 30'); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 62. Selecting Slice of Embedded Documents $post = $dm->query('find title, comments limit 20 skip 10 FROM BlogPost WHERE id = ?', array($id)); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 63. Other Examples // Find all posts greater than or equal to a date $posts = $dm->query('find all FROM BlogPost WHERE createdAt >= ?', array($date)); // Find all posts sorted by created at desc $posts = $dm->query('find all FROM BlogPost sort createdAt desc'); // Update user $dm->query('update DocumentsUser set password = ? where username = ?', array('newpassword', 'jwage')); Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 64. Lifecycle Events Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 65. “A lifecycle event is a regular event with the additional feature of providing a mechanism to register direct callbacks inside the corresponding document classes that are executed when the lifecycle event occurs.” http://www.doctrine-project.org/projects/mongodb_odm/1.0/docs/reference/events/en#lifecycle-callbacks Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 66. preRemove - The preRemove event occurs for a given document before the respective DocumentManager remove operation for that document is executed. • postRemove - The postRemove event occurs for an document after the document has been removed. It will be invoked after the database delete operations. • prePersist - The prePersist event occurs for a given document before the respective DocumentManager persist operation for that document is executed. • postPersist - The postPersist event occurs for an document after the document has been made persistent. It will be invoked after the database insert operations. Generated primary key values are available in the postPersist event. • preUpdate - The preUpdate event occurs before the database update operations to document data. • postUpdate - The postUpdate event occurs after the database update operations to document data. • postLoad - The postLoad event occurs for an document after the document has been loaded into the current DocumentManager from the database or after the refresh operation has been applied to it. Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 67. Event Examples Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 68. /** * @Document * @HasLifecycleCallbacks */ class BlogPost { /** @Id */ public $id; /** @Date */ public $createdAt; /** @Date */ public $updatedAt; /** @PreUpdate */ public function prePersist() { $this->createdAt = new DateTime(); } /** @PreUpdate */ public function preUpdate() { $this->updatedAt = new DateTime(); } } Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 69. Migrating Data Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 70. Initial Document /** * @Document */ class User { /** @Id */ public $id; /** @String */ public $name; } Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 71. New Document /** * @Document */ class User { /** @Id */ public $id; /** @String */ public $firstName; /** @String */ public $lastName; } Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 72. Migrate Documents With Old Field Name /** * @Document * @HasLifecycleCallbacks */ class User { /** @Id */ public $id; /** @String */ public $firstName; /** @String */ public $lastName; /** @PreLoad */ public function preLoad(array &$data) { if (isset($data['name'])) { $e = explode(' ', $data['name']); unset($data['name']); $data['firstName'] = $e[0]; $data['lastName'] = $e[1]; } } Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org
  • 73. Questions? Jonathan H. Wage • http://www.twitter.com/jwage • http://www.jwage.com • http://www.facebook.com/jwage You can contact Jonathan about Doctrine and Open-Source or for training, consulting, application development, or business related questions at jonathan.wage@sensio.com Doctrine MongoDB ODM www.doctrine-project.org www.sensiolabs.org