MongoCursor::batchSize
(PECL mongo >=1.0.11)
MongoCursor::batchSize — Limits the number of elements returned in one batch.
Описание
A cursor typically fetches a batch of result objects and store them locally. This method sets the batchSize value to configure the amount of documents retrieved from the server in one data packet. However, it will never return more documents than fit in the max batch size limit (usually 4MB).
Список параметров
-
batchSize
-
The number of results to return per batch. Each batch requires a round-trip to the server.
If
batchSize
is 2 or more, it represents the size of each batch of objects retrieved. It can be adjusted to optimize performance and limit data transfer.If
batchSize
is 1 or negative, it will limit of number returned documents to the absolute value of batchSize, and the cursor will be closed. For example if batchSize is -10, then the server will return a maximum of 10 documents and as many as can fit in 4MB, then close the cursor.ВниманиеA
batchSize
of 1 is special, and means the same as -1, i.e. a value of 1 makes the cursor only capable of returning one document.Note that this feature is different from MongoCursor::limit() in that documents must fit within a maximum size, and it removes the need to send a request to close the cursor server-side. The batch size can be changed even after a cursor is iterated, in which case the setting will apply on the next batch retrieval.
This cannot override MongoDB's limit on the amount of data it will return to the client (i.e., if you set batch size to 1,000,000,000, MongoDB will still only return 4-16MB of results per batch).
To ensure consistent behavior, the rules of MongoCursor::batchSize() and MongoCursor::limit() behave a little complex but work "as expected". The rules are: hard limits override soft limits with preference given to MongoCursor::limit() over MongoCursor::batchSize(). After that, whichever is set and lower than the other will take precedence. See below. section for some examples.
Возвращаемые значения
Returns this cursor.
Примеры
Пример #1 MongoCursor::batchSize() and combinations with MongoCursor::limit()
<?php
// one batch, at most 10 items. The -10 makes the server to return 10 items,
// and then remove the cursor.
$cursor->limit(20)->batchSize(-10);
// first batch: at most 10 items
$cursor->limit(10);
// first batch: at most 10 items
$cursor->limit(10)->batchSize(20);
// results are fetched in batches of 10 each, with a maximum of 20 items
// returned (that means two batches of 10).
$cursor->limit(20)->batchSize(10);
// results are fetched in batches of 7 each, with a maximum of 30 items
// returned (that means that the driver requests 4 batches of 7, and one batch
// of 2).
$cursor->limit(30)->batchSize(7)
?>
Смотрите также
MongoDB core docs on » batchSize.
- MongoCursor::limit() - Limits the number of results returned
Список изменений
Версия | Описание |
---|---|
1.4.5 |
Before 1.4.5, this method would throw an MongoCursorException if the cursor had already started iterating. |
- 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