You are here

function mongodb_set_active_connection in MongoDB 6

Same name and namespace in other branches
  1. 7 mongodb.module \mongodb_set_active_connection()

Allow for the database connection we are using to be changed.

Parameters

string $alias: The alias that we want to change the connection for.

string $connection_name: The name of the connection we will use.

File

./mongodb.module, line 273
A library of common mechanisms for modules using MongoDB.

Code

function mongodb_set_active_connection($alias, $connection_name = 'default') {

  // No need to check if the connection is valid as mongodb() does this.
  $alias_exists = isset($GLOBALS['conf']['mongodb_collections'][$alias]) && is_array($GLOBALS['conf']['mongodb_collections'][$alias]);
  if ($alias_exists & !empty($GLOBALS['conf']['mongodb_collections'][$alias]['db_connection'])) {
    $GLOBALS['conf']['mongodb_collections'][$alias]['db_connection'] = $connection_name;
  }
  else {
    $GLOBALS['conf']['mongodb_collections'][$alias] = $connection_name;
  }
}