-
Type: Improvement
-
Resolution: Fixed
-
Priority: Major - P3
-
Affects Version/s: None
-
Component/s: Query
https://github.com/mongodb/specifications/blob/master/source/crud/crud.rst#id20
Combining Limit and Batch Size for the Wire Protocol
The OP_QUERY wire protocol only contains a numberToReturn value which drivers must calculate to get expected limit and batch size behavior. Subsequent calls to OP_GET_MORE should use the user-specified batchSize or default to 0. If the result is larger than the max Int32 value, an error MUST be raised as the computed value is impossible to send to the server. Below is pseudo-code for calculating numberToReturn for OP_QUERY.
function calculateFirstNumberToReturn(options: FindOptions): Int32 { Int32 numberToReturn; Int32 limit = options.limit || 0; Int32 batchSize = options.batchSize || 0; if (limit < 0) { numberToReturn = limit; } else if (limit == 0) { numberToReturn = batchSize; } else if (batchSize == 0) { numberToReturn = limit; } else if (limit < batchSize) { numberToReturn = limit; } else { numberToReturn = batchSize; } return numberToReturn; }
Because of this anomaly in the wire protocol, it is up to the driver to enforce the user-specified limit. Each driver MUST keep track of how many documents have been iterated and stop iterating once the limit has been reached. When the limit has been reached, if the cursor is still open, a driver MUST kill the cursor.
- has to be started together with
-
RUBY-2682 Specify 5.0 cursor behaviour
- Closed