Uploaded image for project: 'Java Driver'
  1. Java Driver
  2. JAVA-1255

Add DBCursor.tryNext() method for tailable cursors

    • Type: Icon: New Feature New Feature
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • 2.13.0, 3.0.0
    • Affects Version/s: 2.12.0
    • Component/s: Query Operations
    • Labels:
      None

      In 2.12, the Java driver started setting the AwaitData cursor flag any time the Tailable flag was set. As part of this change, the driver stopped violating the Iterator contractor for cursors. Whereas in previous versions of the driver, an Iterator for a cursor with Tailable but not AwaitData could return false from Iterator.hasNext(), and then some time later return true. In 2.12, by contrast, Iterator.hasNext() for a Tailable cursor blocks until there is a result available or until the cursor has been closed.

      But this change breaks existing clients that were relying on the driver's breaking of the Iterator contract, so the change should be reverted. The driver should allow Tailable without AwaitData, and Iterator.hasNext() for such a cursor will return false but not close the cursor, allowing hasNext() to be called again at a later time.

      Long term, the driver should offer a different API for tailable cursors (perhaps one without a hasNext() method), but this is a short term measure until we get there.

      UPDATE::

      DBCursor now has a tryNext method which may return null if no documents are available, and then return a document on a subsequent call.

            Assignee:
            ross@mongodb.com Ross Lawley
            Reporter:
            jeff.yemin@mongodb.com Jeffrey Yemin
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: