df/silex-doctrine-mongodb-provider

Silex Doctrine MongoDB Provider

1.0.1 2016-08-03 09:40 UTC

This package is not auto-updated.

Last update: 2024-09-14 19:42:13 UTC


README

这是Silex的一个MongoDB服务提供程序,基于Dominik Zogg [email protected] 优秀的存储库 saxulum-doctrine-mongodb-provider,包含一些改进和重构,以兼容silex 2.n/pimple 3.n和PHP 7.n

Software License System Version PHP 7 ready Build Status

特性

  • 支持Silex中的MongoDB(不提供ODM集成)
  • 使用"alcaeus/mongo-php-adapter"作为已废弃的ext-mongo模块的包装器以支持PHP7
  • ODM集成将由 df/silex-doctrine-mongodb-odm-provider 提供(查看详情)

要求

  • PHP >= 5.5.n
  • Silex 2.n (pimple 3.n)
  • Doctrine MongoDb (>= 1.3.0)

安装

使用 composer 安装 df/silex-doctrine-mongodb-provider.

composer require df/silex-doctrine-mongodb-provider 

设置

  • 一个连接的示例
$app->register(new DoctrineMongoDbProvider(), [
    'mongodb.options' => [
        'server' => 'mongodb://localhost:27017',
        'options' => [
            'username' => 'your-username',
            'password' => 'your-password',
            'db' => 'mongo_db_01'
        ]
    ]
]);
  • 多个连接的示例
$app->register(new DoctrineMongoDbProvider(), [
    'mongodbs.options' => [
        'mongodb1' => [
            'server' => 'mongodb://localhost:27017',
            'options' => [
                'username' => 'your-username',
                'password' => 'your-username',
                'db' => 'mongo_db_01'
            ]
        ],
        'mongodb2' => [
            'server' => 'mongodb://localhost:27018',
            'options' => [
                'username' => 'your-username',
                'password' => 'your-username',
                'db' => 'mongo_db_02'
            ]
        ]
    ]
));

使用方法

  • 一个连接的示例
$document = ['key' => 'value'];

$app['mongodb']
    ->selectDatabase('mongo_db_01')
    ->selectCollection('sample')
    ->insert($document)
;
  • 多个连接的示例
$document = ['key' => 'value'];

$app['mongodbs']['mongo1']
    ->selectDatabase('mongo_db_01')
    ->selectCollection('sample')
    ->insert($document)
;

版权