Currently, there is no way for an extending driver to request single-batch result sets in a universal manner suitable for OP_QUERY and the find command. In the case of OP_QUERY, _mongoc_n_return() has an assertion as of 1.3.0 that fails for negative limits. For the find command, there is no way to express singleBatch without using a 3.2+ find command document (I may be overlooking some hacky solution to abuse how query modifiers are merged into the command document).
Changing the private cursor struct to have a signed limit would allow drivers extending libmongoc to pass a negative limit and request that the query return a single batch of results and leave no cursor open on the server. For legacy OP_QUERY operations, this negative limit would be passed as-is (the wire protocol already specifies a signed 32-bit integer for limit). For the find command, a negative limit would be made positive and the singleBatch command option set to true.
Changes would entail revising the assertion in _mongoc_n_return() to operate on the absolute value of the limit, as well as changing the internal struct's field to a signed integer.
Note: the related issue, CDRIVER-1053, refers to changing the public API of mongoc_collection_find() to receive a signed limit.
- is depended on by
-
PHPC-515 Support negative cursor limits for single-batch results
- Closed
- is related to
-
CDRIVER-1053 Make cursor "limit" a signed int64_t
- Closed