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

Incorrect example provided in documentation of list_indexes

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 2.1
    • Affects Version/s: None
    • Component/s: Docs
    • 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 Unassigned
            Reporter:
            olga.v.leyba@gmail.com Olga Leyba
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: