You are here

function MongoCollectionFactory::__construct in MongoDB 8

Parameters

array $mongo:

File

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

Class

MongoCollectionFactory
Creates mongo collections based on settings.

Namespace

Drupal\mongodb

Code

function __construct(array $mongo) {
  $mongo += array(
    'servers' => array(),
  );
  $this->serverInfo = $mongo['servers'];

  // The default server needs to exist.
  $this->serverInfo += array(
    'default' => array(),
  );
  foreach ($this->serverInfo as &$server) {
    $server += array(
      // The default server connection string.
      'server' => 'mongodb://localhost:27017',
      'options' => array(),
    );

    // By default, connect immediately.
    $server['options'] += array(
      'connect' => TRUE,
    );
  }

  // The default database for the default server is 'drupal'.
  $this->serverInfo['default'] += array(
    'db' => 'drupal',
  );
  $this->collectionInfo = isset($mongo['collections']) ? $mongo['collections'] : array();
}