You are here

public function MongoCollectionFactory::get in MongoDB 8

Parameters

string|array $collection_name: If it is an array, the first element contains the prefix, and the second contains the actual collection name.

Return value

\MongoCollection

File

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

Class

MongoCollectionFactory
Creates mongo collections based on settings.

Namespace

Drupal\mongodb

Code

public function get($collection_name) {

  // Avoid something. collection names if NULLs are passed in.
  $args = array_filter(func_get_args());
  if (is_array($args[0])) {
    list($collection_name, $prefixed) = $args[0];
    $prefixed .= $collection_name;
  }
  else {
    $prefixed = implode('.', $args);
    if ($this->testDatabasePrefix = drupal_valid_test_ua()) {
      $prefixed = $this->testDatabasePrefix . $prefixed;
    }
  }
  if (!isset($this->clients[$collection_name])) {
    $server = $this
      ->getServer($collection_name);
    $this->collections[$collection_name] = $this
      ->getClient($server)
      ->selectCollection($server['db'], str_replace('system.', 'system_.', $prefixed));
  }
  return $this->collections[$collection_name];
}