如何通过DriverManager创建doctrine mongodb连接

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.

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);
?>

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.