saxulum / saxulum-doctrine-mongodb-provider

该软件包已被 弃用 并不再维护。作者建议使用 chubbyphp / chubbyphp-laminas-config-doctrine 软件包代替。

Saxulum Doctrine MongoDB Provider

2.1.2 2019-05-29 05:54 UTC

This package is auto-updated.

Last update: 2021-10-02 20:02:09 UTC


README

与 plain silex-php 兼容

Build Status Total Downloads Latest Stable Version

功能

  • 支持 Silex 或 Cilex 中的 mongodb,但它不提供 ODM 集成

需求

  • PHP 5.6+
  • Doctrine Mongodb 1.0 Beta+

安装

通过 Composersaxulum/saxulum-doctrine-mongodb-provider 的形式。

单个连接的示例

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

带自定义 ca 文件的单个连接示例

$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'
        )
    )
));

多个连接的示例

$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'
            )
        )
    )
));

使用

单个连接的示例

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

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

多个连接的示例

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

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

版权