library/Storage/Adapter/Mongo/MongoDbAbstractServiceFactory.php
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        $config = $this->getConfig($serviceLocator)[$requestedName];

        $hosts = array_key_exists('hosts', $config) ? $config['hosts'] : 'localhost:27017';

        $credential = array_key_exists('username', $config) &&
        array_key_exists('password', $config) ?
            "{$config['username']}:{$config['password']}@" :
            null;

        $options = array_key_exists('options', $config) &&
        is_array($config['options']) ?
            $config['options'] :
            [];

        $client = new \MongoClient("mongodb://{$credential}{$hosts}", $options);
        return $client->selectDB($config['database']);
    }
public function createServiceWithName(ServiceLocatorInterface $serviceLocator, $name, $requestedName)
    {
        $config = $this->getConfig($serviceLocator)[$requestedName];

        $hosts = array_key_exists('hosts', $config) ? $config['hosts'] : 'localhost:27017';

        $credential = array_key_exists('username', $config) &&
        array_key_exists('password', $config) ?
            "{$config['username']}:{$config['password']}@" :
            null;

        $options = array_key_exists('options', $config) &&
        is_array($config['options']) ?
            $config['options'] :
            [];

        $client = new \MongoClient("mongodb://{$credential}{$hosts}", $options);
        return $client->selectDB($config['database']);
    }
Create service with name

@param ServiceLocatorInterface $serviceLocator
@param string $name
@param string $requestedName
@return \MongoDB