Uploaded image for project: 'Go Driver'
  1. Go Driver
  2. GODRIVER-2759

Return an error if a "ChangeStream" is invalidated

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Unknown Unknown
    • 3.0.0
    • Affects Version/s: None
    • Component/s: Change Streams
    • None
    • Hide

      1. What would you like to communicate to the user about this feature?
      2. Would you like the user to see examples of the syntax and/or executable code and its output?
      3. Which versions of the driver/connector does this apply to?

      Show
      1. What would you like to communicate to the user about this feature? 2. Would you like the user to see examples of the syntax and/or executable code and its output? 3. Which versions of the driver/connector does this apply to?

      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?

            Assignee:
            Unassigned Unassigned
            Reporter:
            matt.dale@mongodb.com Matt Dale
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated: