Uploaded image for project: 'C Driver'
  1. C Driver
  2. CDRIVER-5925

Apply batchSize:0 to the aggregate for a change stream

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Not Needed
    • C Drivers
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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."

            Assignee:
            kevin.albertson@mongodb.com Kevin Albertson
            Reporter:
            kevin.albertson@mongodb.com Kevin Albertson
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: