Skip to content

Instantly share code, notes, and snippets.

@mhf-ir
Created October 16, 2017 10:59
Show Gist options
  • Save mhf-ir/7cff3c843364b3ab172d72085b89494c to your computer and use it in GitHub Desktop.
Save mhf-ir/7cff3c843364b3ab172d72085b89494c to your computer and use it in GitHub Desktop.
doctrine odm php 7.1 connection uri problem for select database
<?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