Incorrect example provided in documentation of list_indexes

XMLWordPrintableJSON

    • Type: Improvement
    • Resolution: Fixed
    • Priority: Major - P3
    • 2.1
    • Affects Version/s: None
    • Component/s: Docs
    • None
    • None
    • None
    • None
    • None
    • None
    • None

      There's a following example in the docs that does not in fact work:

      async def print_indexes():
          for index in await db.test.list_indexes():
              print(index)
      

      The result of this is "AsyncIOMotorLatentCommandCursor can't be used in 'await' expression" error.

      This example is available here: https://motor.readthedocs.io/en/stable/api-asyncio/asyncio_motor_collection.html#motor.motor_asyncio.AsyncIOMotorCollection.list_indexes

      Correct usage is as follows:

      
      async def print_indexes():
          async for index in db.test.list_indexes():
              print(index)
      
      

      I have tested this and it works. It was advised to me on this forum: https://groups.google.com/forum/?fromgroups#!topic/mongodb-user/KEhu7LK2iDk

       

      Please correct the documentation.

              Assignee:
              Unassigned
              Reporter:
              Olga Leyba
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

                Created:
                Updated:
                Resolved: