You are here

function mongodb_collection in MongoDB 7

Same name and namespace in other branches
  1. 6 mongodb.module \mongodb_collection()
26 calls to mongodb_collection()
Cache::__construct in mongodb_cache/mongodb_cache_plugin.php
Constructor.
drush_mongodb_migrate in mongodb_migrate/mongodb_migrate.drush.inc
Drush callback; migrate all field data into MongoDB.
MongoDBLogTestCase::doUser in mongodb_watchdog/mongodb_watchdog.test
Generate and verify user events.
MongoDBLogTestCase::setUp in mongodb_watchdog/mongodb_watchdog.test
Enable modules and create users with specific permissions.
MongoDBSessionHttpsTestCase::setUp in mongodb_session/mongodb_session.test
Sets up a Drupal site for running functional and integration tests.

... See full list

File

./mongodb.module, line 112
Contains the main module connecting Drupal to MongoDB.

Code

function mongodb_collection() {
  $args = array_filter(func_get_args());
  if (is_array($args[0])) {
    list($collection_name, $prefixed) = $args[0];
    $prefixed .= $collection_name;
  }
  else {

    // Avoid something. collection names if NULLs are passed in.
    $collection_name = implode('.', array_filter($args));
    $prefixed = mongodb_collection_name($collection_name);
  }
  $collections = variable_get('mongodb_collections', array());
  if (isset($collections[$collection_name])) {

    // We might be dealing with an array or string because of need to preserve
    // backwards compatibility.
    $alias = is_array($collections[$collection_name]) && !empty($collections[$collection_name]['db_connection']) ? $collections[$collection_name]['db_connection'] : $collections[$collection_name];
  }
  else {
    $alias = '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
  // object.
  $mongodb_object = mongodb($alias);
  $collection = $mongodb_object
    ->selectCollection(mongodb_collection_name($collection_name));

  // Enable read preference and tags at a collection level if we have 1.3
  // client.
  if (!empty($collections[$alias]['read_preference']) && get_class($mongodb_object->connection) == 'MongoClient') {
    $tags = !empty($collections[$alias]['read_preference']['tags']) ? $collections[$alias]['read_preference']['tags'] : array();
    $collection
      ->setReadPreference($collections[$alias]['read_preference']['preference'], $tags);
  }
  $collection->connection = $mongodb_object->connection;
  return variable_get('mongodb_debug', FALSE) ? new MongoDebugCollection($collection) : $collection;
}