You are here

protected function MongoCollectionFactory::getClient in MongoDB 8

Return value

\MongoClient

File

src/MongoCollectionFactory.php, line 163
Definition of Drupal\mongodb\MongodbBundle.

Class

MongoCollectionFactory
Creates mongo collections based on settings.

Namespace

Drupal\mongodb

Code

protected function getClient($server) {
  $connection_string = $server['server'];
  if (!isset($this->clients[$connection_string])) {
    $client = new \MongoClient($connection_string, $server['options']);
    if (!empty($server['read_preference'])) {
      $client
        ->setReadPreference($server['read_preference']);
    }
    $this->clients[$connection_string] = $client;
  }
  return $this->clients[$connection_string];
}