=== modified file 'sites/all/modules/contrib/mongodb/mongodb.module'
--- sites/all/modules/contrib/mongodb/mongodb.module	2010-04-14 03:21:30 +0000
+++ sites/all/modules/contrib/mongodb/mongodb.module	2010-05-11 19:11:22 +0000
@@ -37,13 +37,25 @@ function mongodb($alias = 'default') {
 }
 
 /**
+ * Loads the mongo colelction and creates a global.
+ */
+function mongodb_get_collections() {
+  // Have we loaded the mongo collection data if not load it.
+  if (!isset($GLOBALS['mongodb_collections'])) {
+    $GLOBALS['mongodb_collections'] = variable_get('mongodb_collections', array());
+  }
+
+  return $GLOBALS['mongodb_collections'];
+}
+
+/**
  * Returns a MongoCollection object.
  */
 function mongodb_collection($collection_name) {
   $args = func_get_args();
   // Avoid something. collection names if NULLs are passed in.
   $collection_name = implode('.', array_filter($args));
-  $collections = variable_get('mongodb_collections', array());
+  $collections = mongodb_get_collections();
   $alias = isset($collections[$collection_name]) ? $collections[$collection_name] : 'default';
   // Prefix the collection name for simpletest. It will be in the same DB as the
   // non-prefixed version so it's enough to prefix after choosing the mongodb
@@ -90,6 +102,22 @@ function mongodb_test_group_finished() {
 }
 
 /**
+ * Allow for the database connection we are using to be changed.
+ *
+ * @param $alias
+ *   String the alias that we want to change the connection for.
+ * @param $connection_name
+ *   String the name of the connection we will use.
+ */
+function mongodb_set_active_connection($alias, $connection_name = 'default') {
+  // Ensure we have a valid mongodb collection object.
+  mongodb_get_collections();
+
+  // No need to check if the connection is valid as mongodb() does this.
+  $GLOBALS['mongodb_collections'][$alias] = $connection_name;
+}
+
+/**
  * Return the next id in a sequence.
  */
 function mongodb_next_id($name) {

