-
Type: Improvement
-
Resolution: Unresolved
-
Priority: Unknown
-
Affects Version/s: None
-
Component/s: Change Streams
-
None
Currently, if users are iterating a ChangeStream, they have to check both stop conditions Err() != nil (i.e. "there was an error") and if ID() == 0 (i.e. "the server invalidated the cursor"). For example:
for { if c.TryNext(...) { // Use the result. } if c.Err() != nil { panic(c.Err()) } if c.ID() == 0 { break } }
A more obvious pattern is to return an error if the server invalidates the cursor. In that case, users only need to check Err() != nil.
Open questions:
- Are users still able to differentiate between errors and server-invalidated change stream cursors (i.e. will ID() only return 0 for invalidated change streams, or any error)?
- Should we implement the same behavior for tailable cursors?