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

Collection is defined like Iterable but actually isn’t

    XMLWordPrintable

Details

    • Bug
    • Status: Closed
    • Major - P3
    • Resolution: Fixed
    • None
    • 4.1
    • None

    Description

       

      If you define {{_iter}} python considers the object is {{Iterable}}. If you define it why {{next_}} raise an error? and why alias to Collection.{{next()}} if it will do nothing? I dont understand.

       

      Minimal example:

      from typing import Iterable
       
      import pymongo
       
      mongo_client = pymongo.MongoClient("localhost", 27017)
      db = mongo_client.database_1
       
      print(db.user)
      print(f'Is iterable -> {isinstance(db.user, Iterable)}')
       
      try:
          print(list(db.user))
      except Exception as e:
          print(e)
       
      try:
          print(next(db.user))
      except Exception as e:
          print(e)
       
      try:
          print(db.user.next())
      except Exception as e:
          print(e)
      

      {{}}

       

      Output:

       

      Collection(Database(MongoClient(host=['localhost:27017'], document_class=dict, tz_aware=False, connect=True), 'database_1'), 'user')
      Is iterable -> True
      'Collection' object is not iterable
      'Collection' object is not iterable
      'Collection' object is not iterable

       

       

      Mongo community forum issue:

      https://www.mongodb.com/community/forums/t/collection-is-defined-like-iterable-but-actually-isnt/134683

      Attachments

        Issue Links

          Activity

            People

              shane.harvey@mongodb.com Shane Harvey
              correobasurafamiliar@gmail.com Flanagan Vaquero
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: