MongoDB\Driver\Manager
PHP Manual

MongoDB\Driver\Manager::executeCommand

(mongodb >=0.2.0)

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

Description

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

Executes command on a MongoDB server matching readPreference.

Liste de paramètres

db

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

command

The command document.

readPreference

Optionnellement, une MongoDB\Driver\ReadPreference vers laquelle la commande sera routée. Si rien n'est fourni, ce sera les préférences de lecture définies par l' URI de connexion MongoDB.

Valeurs de retour

Returns MongoDB\Driver\Cursor on success, lance une exception (une instance de la classe MongoDB\Driver\Exception) en cas d'échec.

Erreurs / Exceptions

Exemples

Exemple #1 MongoDB\Driver\Manager::executeCommand() example

<?php

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

try {
    
$cursor $manager->executeCommand("admin"$command);
    
$response $cursor->toArray()[0];
} catch(
MongoDB\Driver\Exception $e) {
    echo 
$e->getMessage(), "\n";
    exit;
}
var_dump($response);

?>

L'exemple ci-dessus va afficher quelque chose de similaire à :


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

Notes

Note:

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

Note:

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.

Voir aussi


MongoDB\Driver\Manager
PHP Manual