ulff / php-mongodb-client-bundle

安装: 5

依赖: 0

建议者: 0

安全: 0

星标: 0

关注者: 2

分支: 0

开放问题: 0

类型:symfony-bundle

dev-master 2017-09-29 12:59 UTC

This package is not auto-updated.

Last update: 2024-09-15 04:20:53 UTC


README

一个用于MongoDB的Symfony包。与新的mongodb驱动程序兼容,而doctrine/mongodb仅与已废弃且不再支持的mongo驱动程序兼容。

查看:https://docs.mongodb.com/ecosystem/drivers/php/#compatibility

安装和配置

步骤 1:安装包

使用 composer 安装包

php composer.phar require "ulff/php-mongodb-client-bundle:dev-master"

在 AppKernel.php 中启用包

// app/AppKernel.php

public function registerBundles()
{
    $bundles = [
        // ...
        new Ulff\PhpMongodbClientBundle\UlffPhpMongodbClientBundle(),
    ];

    // ...
}

步骤 2:添加包配置

将配置添加到 config.yml。最小需求是

# app/config/config.yml

ulff_php_mongodb_client:
    connection:
        host: hostname-here

还有其他配置选项,例如

# app/config/config.yml

ulff_php_mongodb_client:
    connection:
        host: hostname-here
        port: 27017               # optional, default 27017
        username: username-here   # optional, default not set
        password: password-here   # optional, default not set
    options: { }
        # any custom connection options here, passed as assoc array

将值替换为正确的值。

用法

客户端使用

Mongodb 客户端作为服务可用

$client = $this->get('ulff_php_mongodb_client.client');

获取管理器

服务提供对mongodb管理器的访问

$manager = $this->get('ulff_php_mongodb_client.client')->getManger();