-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Minor - P4
-
None
-
Affects Version/s: None
-
Component/s: None
-
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.
- is related to
-
PHPLIB-451 Rewinding change stream cursor should never execute a getMore command
- Closed