function mongodb_collection in MongoDB 6
Same name and namespace in other branches
- 7 mongodb.module \mongodb_collection()
Returns a MongoCollection object.
10 calls to mongodb_collection()
- 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.
- mongodb_watchdog_clear_log_submit in mongodb_watchdog/
mongodb_watchdog.admin.inc - Submit callback: clear database with log messages.
- mongodb_watchdog_ensure_indexes in mongodb_watchdog/
mongodb_watchdog.install - Create an index for the watchdog table.
- mongodb_watchdog_event in mongodb_watchdog/
mongodb_watchdog.admin.inc - Display watchdogs entry details in MongoDB.
File
- ./
mongodb.module, line 75 - A library of common mechanisms for modules using 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 comptability.
$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;
}