Skip to content
This repository has been archived by the owner on Oct 3, 2021. It is now read-only.

saxulum-legacy/saxulum-doctrine-mongodb-provider

Repository files navigation

saxulum-doctrine-mongodb-provider

works with plain silex-php

Build Status Total Downloads Latest Stable Version

Features

  • Support for mongodb within Silex or Cilex, it does NOT PROVIDE the ODM integration

Requirements

  • PHP 5.6+
  • Doctrine Mongodb 1.0 Beta+

Installation

Through Composer as saxulum/saxulum-doctrine-mongodb-provider.

Example for one connection:

$app->register(new DoctrineMongoDbProvider(), array(
    'mongodb.options' => array(
        'server' => 'mongodb://localhost:27017',
        'options' => array(
            'username' => 'root',
            'password' => 'root',
            'db' => 'admin'
        )
    )
));

Example for one connection with custom ca file:

$app->register(new DoctrineMongoDbProvider(), array(
    'mongodb.options' => array(
        'server' => 'mongodb://localhost:27017',
        'options' => array(
            'username' => 'root',
            'password' => 'root',
            'db' => 'admin'
        ),
        'driverOptions => array(
            'ca_file' => '/some/ca.pem'
        )
    )
));

Example for multiple connections:

$app->register(new DoctrineMongoDbProvider(), array(
    'mongodbs.options' => array(
        'mongo1' => array(
            'server' => 'mongodb://localhost:27017',
            'options' => array(
                'username' => 'root',
                'password' => 'root',
                'db' => 'admin'
            )
        ),
        'mongo2' => array(
            'server' => 'mongodb://localhost:27018',
            'options' => array(
                'username' => 'root',
                'password' => 'root',
                'db' => 'admin'
            )
        )
    )
));

Usage

Example for one connection:

$document = array('key' => 'value');

$app['mongodb']
    ->selectDatabase('saxulum-doctrine-mongodb-provider')
    ->selectCollection('sample')
    ->insert($document)
;

Example for multiple connections:

$document = array('key' => 'value');

$app['mongodbs']['mongo1']
    ->selectDatabase('saxulum-doctrine-mongodb-provider')
    ->selectCollection('sample')
    ->insert($document)
;

Copyright