Contenu connexe Similaire à Doctrine MongoDB ODM (PDXPHP) (20) Plus de Kris Wallsmith (14) Doctrine MongoDB ODM (PDXPHP)2. @kriswallsmith
• Symfony Release Manager
• Doctrine Team
• Senior Software Engineer at
• 10 years experience with PHP and web development
• Open source evangelist and international speaker
4. $mongo = new Mongo();
$db = $mongo->pdxphp;
$db->people->save(array(
'name' => 'Kris Wallsmith',
));
6. Array
(
[4cbdffdae84ded424f000000] => Array
(
[_id] => MongoId Object
[name] => Kris Wallsmith
)
)
9. $query = array('roles' => 'presenter');
$cursor = $db->people->find($query);
print_r(iterator_to_array($cursor));
10. Array
(
[4cbe03cfe84dedb850010000] => Array
(
[_id] => MongoId Object
[name] => Sam Keen
[roles] => Array
(
[0] => organizer
[1] => presenter
)
)
)
12. $query = array(
'name' => 'Kris Wallsmith',
);
$kris = $db->people->findOne($query);
$kris['roles'] = array('presenter');
$db->people->save($kris);
13. $query = array('roles' => 'presenter');
$fields = array('name');
$cursor = $db->people->find($query, $fields);
print_r(iterator_to_array($cursor));
14. Array
(
[4cbe0a9de84ded7952010000] => Array
(
[_id] => MongoId Object
[name] => Sam Keen
)
[4cbe0a9de84ded7952000000] => Array
(
[_id] => MongoId Object
[name] => Kris Wallsmith
)
)
16. $query = array('roles' => 'presenter');
$update = array(
'$push' => array(
'roles' => 'cool guy',
),
);
$db->people->update($query, $update);
27. Terminology
RDBMS MongoDB
Database Database
Table Collection
Row Document
Foreign Key Database Reference
33. /** @Document(collection="people") */
class Person {
/** @Id */
public $id;
/** @String */
public $name;
/** @Collection */
public $roles = array();
/** @ReferenceMany */
public $likes = array();
/** @EmbedMany(targetDocument="Address") */
public $addresses = array();
}
35. $kris = new Person();
$kris->name = 'Kris Wallsmith';
$kris->roles[] = 'presenter';
$kris->likes[] = $sam;
$kris->addresses[] = $homeAddy;
$documentManager->persist($kris);
$documentManager->flush();
46. /** @Document @HasLifecycleCallbacks */
class Foo
{
/** @Timestamp */
public $createdAt;
/** @PrePersist */
public function ensureCreatedAt() {
$this->createdAt = new DateTime();
}
}
47. OpenSky is Hiring!
http://engineering.shopopensky.com
Please contact me if you're interested.
48. OpenSky is Hiring!
http://engineering.shopopensky.com
Please contact me if you're interested.