php8.5
Home/ Manual/ driver / server/ MongoDB\Driver\Server::executeCommand

MongoDB\Driver\Server::executeCommand

PHP function Edit on GitHub ✎

(mongodb >=1.0.0)

Execute a database command on this server

Description

MongoDB\Driver\Server::executeCommand(string $db, MongoDB\Driver\Command $command, array|null $options = null): MongoDB\Driver\Cursor

Executes the command on this server.

This method applies no special logic to the command. The Default values for the "readPreference", "readConcern", and "writeConcern" options will be inferred from an active transaction (indicated by the "session" option). If there is no active transaction, a primary read preference will be used for server selection.

Default values will not be inferred from the connection URI. Users are therefore encouraged to use specific read and/or write command methods if possible.

Readpreference

Parameters

options
OptionTypeDescription

TransactionReadWriteConcern

Return Values Cursor

Errors/Exceptions

  • Throws MongoDB\Driver\Exception\RuntimeException on other errors (e.g. invalid command, issuing a write command to a secondary).

Changelog

VersionDescription
PECL mongodb 2.0.0The options parameter no longer accepts a MongoDB\Driver\ReadPreference instance.
PECL mongodb 1.21.0Passing a MongoDB\Driver\ReadPreference object as options is deprecated and will be removed in 2.0.
PECL mongodb 1.4.4MongoDB\Driver\Exception\InvalidArgumentException will be thrown if the "session" option is used in combination with an unacknowledged write concern.
PECL mongodb 1.4.0The third parameter is now an options array. For backwards compatibility, this parameter will still accept a MongoDB\Driver\ReadPreference object.

Notes Write

See Also

Source: reference/mongodb/mongodb/driver/server/executecommand.xml · from the official PHP manual (php/doc-en)