Add 'HasNext' method to Cursor type

XMLWordPrintableJSON

    • Type: New Feature
    • Resolution: Won't Fix
    • Priority: Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: CRUD
    • None
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      Because cursors are lazy, there's currently no way to know if the initial query fails until the first document is retrieved.  The shell and some drivers offer a  hasNext method on cursors that eagerly evaluates the query.

      There are some cases where knowing the success of a query in advance of iteration simplifies the user's code. For example, one part of the code might execute the query (and handle an error) and pass the iterator to another part for processing.  Without a HasNext type function, one has to retrieve the first document to check for error and pass the first document plus the iterator for processing.

      The semantics for HasNext should be:

      • If the query has not been sent, send it.
      • If we didn't just send the query and if the cursorId is non-zero and if the current batch has no documents remaining, send getMore to retrieve another batch.
      • If the cursor is in an error state, return false.
      • If there is at least one document remaining in the current batch, return true
      • Otherwise, return false.

      By sending only a single query or getMore, we avoid doing more than one network roundtrip. This is the best answer to the question "what would happen if I called Next"?

            Assignee:
            Unassigned
            Reporter:
            David Golden
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: