Uploaded image for project: 'PHP Driver: Library'
  1. PHP Driver: Library
  2. PHPLIB-448

ChangeStream::rewind() should throw if called after advancing beyond first result

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Minor - P4 Minor - P4
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      The rewind handler for MongoDB\Driver\Cursor will throw a LogicException if it is invoked any time after iteration has advanced beyond the first element. Rewinding multiple times at the start of a cursor is a NOP.

      Since a change stream wraps a tailable cursor, it has the same behavior; however, there exists an edge case where a user could call ChangeStream::rewind() after previously iterating with next() and not encounter an exception. When a change stream resumes (possible during any call to rewind() or next()) it recreates the wrapped cursor and rewinds it. If the user were to call ChangeStream::rewind() after a previous call the ChangeStream::rewind() or ChangeStream::next() that resumed, that rewind would be a NOP and not throw a LogicException.

      Rather than rely on MongoDB\Driver\Cursor, we may want to add a check within ChangeStream::rewind() and throw if we've previously advanced beyond the first element of the change stream (regardless of whether we've just resumed or not). This would make change stream iteration more consistent with that of a normal, non-resumable cursor.

            Assignee:
            Unassigned Unassigned
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: