MongoCursor::slaveOkay
(PECL mongo >=0.9.4)
MongoCursor::slaveOkay — Sets whether this query can be done on a secondary [deprecated]
Описание
This method is deprecated since version 1.5.0. Instead, please use MongoCursor::setReadPreference() and Read Preferences.
Calling this will make the driver route reads to secondaries if:
- You are using a replica set, and
- You created a MongoClient instance using the option "replicaSet" => "setName", and
- There is a healthy secondary that can be reached by the driver.
Note that you should use this function even if you do not use the automatic routing to secondaries. If you connect directly to a secondary in a replica set, you still need to call this function, which basically tells the database that you are aware that you might be getting older data and you're okay with that. If you do not call this, you'll get "not master" errors when you try to query.
This method will override the static class variable MongoCursor::$slaveOkay. It will also override Mongo::setSlaveOkay(), MongoDB::setSlaveOkay() and MongoCollection::setSlaveOkay().
Список параметров
-
okay
-
If it is okay to query the secondary.
Возвращаемые значения
Returns this cursor.
Ошибки
Throws MongoCursorException if this cursor has started iterating.
Примеры
Пример #1 MongoCursor::slaveOkay() example
<?php
MongoCursor::$slaveOkay = false;
// cannot query secondary
$cursor = $collection->find();
// can query secondary
$cursor = $collection->find()->slaveOkay();
MongoCursor::$slaveOkay = true;
// can query secondary
$cursor = $collection->find();
// cannot query secondary
$cursor = $collection->find()->slaveOkay(false);
?>
Смотрите также
- Read Preferences
- MongoCursor::setReadPreference() - Set the read preference for this query
- MongoCursor::getReadPreference() - Get the read preference for this query
Список изменений
Версия | Описание |
---|---|
1.5.0 | This method has been deprecated in favour of MongoCursor::setReadPreference() and Read Preferences. |
- PHP Руководство
- Функции по категориям
- Индекс функций
- Справочник функций
- Расширения для работы с базами данных
- Расширения для работы с базами данных отдельных производителей
- MongoDB
- Базовые классы
- Функция MongoCursor::addOption() - Adds a top-level key/value pair to a query
- Функция MongoCursor::awaitData() - Sets whether this cursor will wait for a while for a tailable cursor to return more data
- Функция MongoCursor::batchSize() - Limits the number of elements returned in one batch.
- Функция MongoCursor::__construct() - Create a new cursor
- Функция MongoCursor::count() - Counts the number of results for this query
- Функция MongoCursor::current() - Returns the current element
- Функция MongoCursor::dead() - Checks if there are documents that have not been sent yet from the database for this cursor
- Функция MongoCursor::doQuery() - Execute the query.
- Функция MongoCursor::explain() - Return an explanation of the query, often useful for optimization and debugging
- Функция MongoCursor::fields() - Sets the fields for a query
- Функция MongoCursor::getNext() - Return the next object to which this cursor points, and advance the cursor
- Функция MongoCursor::getReadPreference() - Get the read preference for this query
- Функция MongoCursor::hasNext() - Checks if there are any more elements in this cursor
- Функция MongoCursor::hint() - Gives the database a hint about the query
- Функция MongoCursor::immortal() - Sets whether this cursor will timeout
- Функция MongoCursor::info() - Gets the query, fields, limit, and skip for this cursor
- Функция MongoCursor::key() - Returns the current result's _id
- Функция MongoCursor::limit() - Limits the number of results returned
- Функция MongoCursor::maxTimeMS() - Sets a server-side timeout for this query
- Функция MongoCursor::next() - Advances the cursor to the next result
- Функция MongoCursor::partial() - If this query should fetch partial results from mongos if a shard is down
- Функция MongoCursor::reset() - Clears the cursor
- Функция MongoCursor::rewind() - Returns the cursor to the beginning of the result set
- Функция MongoCursor::setFlag() - Sets arbitrary flags in case there is no method available the specific flag
- Функция MongoCursor::setReadPreference() - Set the read preference for this query
- Функция MongoCursor::skip() - Skips a number of results
- Функция MongoCursor::slaveOkay() - Sets whether this query can be done on a secondary [deprecated]
- Функция MongoCursor::snapshot() - Use snapshot mode for the query
- Функция MongoCursor::sort() - Sorts the results by given fields
- Функция MongoCursor::tailable() - Sets whether this cursor will be left open after fetching the last results
- Функция MongoCursor::timeout() - Sets a client-side timeout for this query
- Функция MongoCursor::valid() - Checks if the cursor is reading a valid result.
Коментарии
404 Not Found