<?php

//Create and instance of Morph_Storage passing in the appropriate database
$mongo = new Mongo();
$storage = new Morph_Storage($mongo->selectDb('myDB'));
//Find a maximum of 10 users that has more than 15 posts, skipping the first 10
$query = new Morph_Query();
$query->limit(10)->skip(10)->property('numberOfPosts')->greaterThan(15);
$users = $storage->findByQuery(new User(), $query);
<?php
//Initialise Morph_Storage passing in the appropriate database
$mongo = new Mongo();
Morph_Storage::init($mongo->selectDb('myDB'));;

//Find users with the userName = j.d.moss
$user = new User();
$query = new Morph_Query();
$query->property('userName')->equals('j.d.moss');
$users = $user->findByQuery($query);
Exemple #3
0
<?php

//Create and instance of Morph_Storage passing in the appropriate database
$mongo = new Mongo();
$storage = new Morph_Storage($mongo->selectDb('myDB'));
$query = new Morph_Query();
$query->property('createdDate')->greaterThan(MongoDate(time() - 604800))->lessThan(new MondoDate(time()))->property('cost')->greaterThanOrEqualTo(12.99)->property('publisher')->in(array('publisherA', 'publisherB', 'publisherC'));
/**
 * This query is roughly equivalent to the sql:
 * SELECT * FROM `ABook` WHERE
 *     `createdDate` > DATE_SUB(now(), INTERVAL 1 WEEK)
 * AND `createdDate` < now()
 * AND `cost` >= 12.99
 * AND `publisher` in ('publisherA', 'publisherB', 'publisherC');
 */
$users = $storage->findByQuery(new A_Book(), $query);
<?php

//Create and instance of Morph_Storage passing in the appropriate database
$mongo = new Mongo();
$storage = new Morph_Storage($mongo->selectDb('myDB'));
//Create and instance of our user class
$user = new User();
$user->firsName = 'Jonathan';
$user->lastName = 'Moss';
$user->userName = '******';
$user->dateOfBirth = strtotime('1978-09-12');
//Store that baby!
$storage->save($user);
<?php

//Create and instance of Morph_Storage passing in the appropriate database
$mongo = new Mongo();
$storage = new Morph_Storage($mongo->selectDb('myDB'));
//Fetches and instance of User by its id
$user = $storage->fetchById(new User(), 1234);
//do something with it's properties
echo $user->firstName;