Uploaded image for project: 'Motor'
  1. Motor
  2. MOTOR-1014

Allow cursor to be used in async with-statement

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 3.1
    • Affects Version/s: None
    • Component/s: None
    • None

      Allow find/aggregate cursors to be used in async with-statements. Reported here: https://github.com/mongodb/motor/pull/172

      When I use the following code:

      async with self.coll.find() as cursor:
          async for record in cursor:
              yield record
      

      It's going to throw an AttributeError.
      So I added the asynchronous context manager method so that I did not have to close the cursor when I was done with it

            Assignee:
            julius.park@mongodb.com Julius Park (Inactive)
            Reporter:
            shane.harvey@mongodb.com Shane Harvey
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: