Execute a MongoDB database command


(mongodb >=0.2.0)

MongoDB\Driver\Manager::executeCommandExecute a MongoDB database command

Описание

final public MongoDB\Driver\Result MongoDB\Driver\Manager::executeCommand ( string $db , MongoDB\Driver\Command $command [, MongoDB\Driver\ReadPreference $readPreference ] )

Executes command on a MongoDB server matching readPreference.

Список параметров

db

The name of the database on which to execute the command.

command

The command document.

readPreference

Optionally, a MongoDB\Driver\ReadPreference to route the command to. If none given, defaults to the Read Preferences set by the MongoDB Connection URI.

Возвращаемые значения

Returns MongoDB\Driver\Result on success, throws exception (instanceof MongoDB\Driver\Exception) on failure.

Ошибки

Примеры

Пример #1 MongoDB\Driver\Manager::executeCommand() example

<?php

$manager 
= new MongoDB\Driver\Manager("mongodb://localhost:27017");
$command = new MongoDB\Driver\Command(array("ping" => 1));

try {
    
$result $manager->executeCommand("admin"$command);
    
$response $result->getResponseDocument();
} catch(
MongoDB\Driver\Exception $e) {
    echo 
$e->getMessage(), "\n";
    exit;
}
var_dump($response);

?>

Результатом выполнения данного примера будет что-то подобное:

  array(1) {   ["ok"]=>   float(1) }  

Примечания

Замечание:

For write commands, MongoDB\Driver\WriteConcern is included in the command document itself.

Замечание:

If a secondary readPreference is used, it is the caller's responsibility to ensure that the command can be executed on a secondary. No validation is done by the driver.

Смотрите также