Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-2443

Adjust batch size based on limit & remaining # of documents

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.18.0
    • Affects Version/s: None
    • Component/s: Query
    • Labels:

      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.

            Assignee:
            neil.shweky@mongodb.com Neil Shweky (Inactive)
            Reporter:
            oleg.pudeyev@mongodb.com Oleg Pudeyev (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: