/Mongroove

Mongo DB php ODM

Primary LanguagePHPBSD 3-Clause "New" or "Revised" LicenseBSD-3-Clause

Mongroove

Mongroove is an ODM (Object Document Mapper) for MongoDB. This ODM is compatible with PHP 5.2 and after and it respect PEAR class naming convention.

Warning this is an alpha version, do not use in a production environment !

Simple usage:

Autoload and initialise the manager

require_once 'includes/Mongroove.php';
spl_autoload_register(array('Mongroove', 'autoload'));

$manager = Mongroove_Manager::getInstance();

Open a new connection with the database

$manager->openConnection('host=localhost:27017;dbname=admin');

Retrieve a document

$cursor = Mongroove::getCollection('users')->createQuery()->getQuery()->execute();
print_r($cursor->toArray());

Aggregation Framework:

$cursor = Mongroove::getCollection('users')->aggregate(
    array('$match' => array('id_str' => array('$lt' => 10))),
    array('$group' => array('_id' => null, 'nb_posts' => array('$sum' => '$total_posts'), 'nb_document' => array('$sum' => 1)))
);
print_r($cursor->toArray());