Is there a way to create mongodb connection using doctrine's DriverManager::getConnection() method? Most of examples use yaml file to configure connections. I am looking for a way to make doctrine-mongodb connections only with php code.
Asked
Active
Viewed 1,930 times
2 Answers
2
Doctrine\DBAL\DriverManager
is not related to the doctrine/mongodb library. DBAL is an analogous to doctrine/mongodb in that they're both database abstraction layers w/o the modeling aspect, but DBAL is specific to SQL drivers (e.g. PDO, DB2).
In DBAL, there are various driver classes, and the manager class merely abstracts their construction. For doctrine/mongodb, there is no need for a manager since MongoDB connections all use the PECL driver's own MongoClient class. Constructing a Doctrine\MongoDB\Connection
instance will be sufficient.

jmikola
- 6,892
- 1
- 31
- 61
0
Looking at the Doctrine ODM Introduction docs, this seems to be the correct way:
<?php
use Doctrine\ODM\MongoDB\DocumentManager;
use Doctrine\MongoDB\Connection;
$connection = new Connection();
$dm = DocumentManager::create($connection, $config);
?>

bjori
- 2,064
- 1
- 15
- 15