(mongodb >=1.0.0)
MongoDB\Driver\Server::executeCommand — Execute a database command on this server
$db, MongoDB\Driver\Command $command, ?array $options = null): MongoDB\Driver\CursorExecutes 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"впливає не на сервер, котрому драйвер дає команду, а тільки на об'єкт сервера. Натомість, під час надсилання драйвером команди, цей параметр може забезпечувати відповідний мережевий протокол для другорядного вузла з набору реплік, а також встановлювати вимоги щодо читання для mongo-вузла.
db (string)Назва бази даних, в якій буде виконано команду.
command (MongoDB\Driver\Command)Команда, яку потрібно виконати.
options
| Option | Type | Description |
|---|---|---|
| readConcern | MongoDB\Driver\ReadConcern |
Вимога щодо зчитування. Цей параметр доступний в MongoDB 3.2+, тож його застосування у старіших версіях викине виключення під час виконання. |
| readPreference | MongoDB\Driver\ReadPreference |
Параметр читання для вибору сервера для операції. |
| session | MongoDB\Driver\Session |
Сеанс, по'язаний з операцією. |
| writeConcern | MongoDB\Driver\WriteConcern |
Вимога щодо запису. |
Для сеансу ("session") транзакції, яка триває, не
можна задати параметр "readConcern" або
"writeConcern". Це призведе до викидання виключення
MongoDB\Driver\Exception\InvalidArgumentException.
Ці два параметри потрібно задавати під час створення транзакції методом
MongoDB\Driver\Session::startTransaction().
У разі успіху повертає примірника MongoDB\Driver\Cursor.
"session" використано разом з параметром
"readConcern" або "writeConcern",
викидається
MongoDB\Driver\Exception\InvalidArgumentException."session", а вимога щодо запису не задоволена, викидається
MongoDB\Driver\Exception\InvalidArgumentException.
| Версія | Опис |
|---|---|
| PECL mongodb 2.0.0 |
The options parameter no longer accepts a
MongoDB\Driver\ReadPreference instance.
|
| PECL mongodb 1.21.0 |
Passing a MongoDB\Driver\ReadPreference object as
options is deprecated and will be removed in 2.0.
|
| PECL mongodb 1.4.4 |
MongoDB\Driver\Exception\InvalidArgumentException
will be thrown if the "session" option is used in
combination with an unacknowledged write concern.
|
| PECL mongodb 1.4.0 |
The third parameter is now an options array.
For backwards compatibility, this paramater will still accept a
MongoDB\Driver\ReadPreference object.
|
Зауваження: На програміста покладено роль визначити спроможність сервера виконувати операції запису. До прикладу, операція запису на другорядному вузлі (за винятком "локальної" БД) буде невдалою.