Created
October 16, 2017 10:59
-
-
Save mhf-ir/7cff3c843364b3ab172d72085b89494c to your computer and use it in GitHub Desktop.
doctrine odm php 7.1 connection uri problem for select database
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php declare(strict_types=1); | |
namespace MyApp\Container; | |
use Doctrine\MongoDB\Connection; | |
use Doctrine\ODM\MongoDB\Configuration; | |
use Doctrine\ODM\MongoDB\DocumentManager; | |
use Doctrine\ODM\MongoDB\Mapping\Driver\AnnotationDriver; | |
AnnotationDriver::registerAnnotationClasses(); | |
$connection = new Connection('mongodb://mongodb:27017/app'); // will not select `app` database | |
$config = new Configuration(); | |
$config->setDefaultDB('app'); // i must set as configuraion | |
$config->setProxyDir('/app/var/cache'); | |
$config->setProxyNamespace('Proxies'); | |
$config->setHydratorDir('/app/var/cache'); | |
$config->setHydratorNamespace('Hydrators'); | |
$config->setMetadataDriverImpl(AnnotationDriver::create('/app/app/src/Model')); | |
$dm = DocumentManager::create($connection, $config); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment