-
Type:
Improvement
-
Resolution: Unresolved
-
Priority:
Major - P3
-
None
-
Affects Version/s: None
-
Component/s: None
-
None
-
Not Needed
-
C Drivers
Scope
Apply batchSize:0 to the aggregate command sent for a change stream.
Background & Motivation
The C driver ignores batchSize:0 when creating a change stream. This results in using the server default for both the "aggregate" and "getMore" commands. Behavior for batchSize:0 differs between in drivers.
In the C++ driver (full example):
mongocxx::options::change_stream options;
options.batch_size(0);
mongocxx::change_stream stream = collection.watch(options); // Does not send batchSize for aggregate or getMore.
In PyMongo (full example):
with collection.watch(batch_size=0) as stream: # Sends batchSize:0 for aggregate. Does not send batchSize for getMore.
Sending batchSize:0 can help bound the time of long-running "aggregate" commands. Applying batchSize:0 results in the "aggregate" immediately returning with no results. The subsequent "getMore" commands can be time-bounded with the maxAwaitTimeMS option. Quoting HELP-29972:
Both the aggregate command and find command support establishing a cursor with batchSize:0 exactly for this reason
DRIVERS-1589 proposes a long-term solution for all drivers. The linked WRITING-10467 proposes a new option (emptyInitialBatch). This ticket proposes a non-API short-term solution.
Caveats
- This is a subtle behavior change. Though specifying batchSize:0 for change streams in the C driver is currently ignored.
- Respecting batchSize:0 may be an unexpected difference between change stream and other cursor returning operations. Though the C driver documentation does not specify behavior for batchSize:0 in change streams, it does specify the behavior for mongoc_cursor_set_batch_size: "If the batch size is zero, the cursor uses the server-defined maximum batch size."
- is depended on by
-
SERVER-101934 Streams: set the batch size to 0 on watch calls
-
- Needs Scheduling
-