Uploaded image for project: 'Python Driver'
  1. Python Driver
  2. PYTHON-1662

Add method to request the next ChangeStream document without blocking forever

    • Type: Icon: New Feature New Feature
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.8
    • Affects Version/s: None
    • Component/s: None
    • None

      Python's ChangeStream implementation provides a single method, next, to retrieve the next document. next loops forever running getMores until the server returns the next document.

      We could add a way to request the next document without running multiple getMores with a try_next method equivalent to Java's tryNext (JAVA-2968) and Ruby's try_next, which runs a single getMore and returns the next document or None.

      change_stream = # Create change stream
      while change_stream.alive:
          change = change_stream.try_next()
          if change is None:
              # No new changes, do something else...
              pass
          else:
              # Process the next change
              print(change)
      

            Assignee:
            shane.harvey@mongodb.com Shane Harvey
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            2 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: