Silex provider for MongoDB integration via Doctrine

Installs: 153

Dependents: 1

Stars: 1

Watchers: 1

Forks: 2

Language: PHP

1.0 2013-02-23 16:30 UTC


A Doctrine-MongoDB provider for the Silex micro-framework.


Registering the provider creates a few services under a given namespace. The provider can be registered multiple times if multiple connections are needed.

Basic Usage:

//Register services under the 'mongodb' namespace, with no custom configuration (empty array)
$app->register(new \Devture\SilexProvider\DoctrineMongoDB\ServicesProvider('mongodb', array()));

//Get a reference to a database on that server connection
$app['db'] = $app->share(function ($app) {
        return $app['mongodb.connection']->selectDatabase('database_name');

Advanced Usage:

//See the docs for \MongoClient ( for connection string format and options
$configuration = array(
        'server' => 'mongodb://',
        'options' => array(
                'connect' => true,
                'connectTimeoutMS' => 200,

$app->register(new \Devture\SilexProvider\DoctrineMongoDB\ServicesProvider('mongodb', $configuration));

$app['db_main'] = $app->share(function ($app) {
        return $app['mongodb.connection']->selectDatabase('database_name');

$app['db_other'] = $app->share(function ($app) {
        return $app['mongodb.connection']->selectDatabase('another_database_name');