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

Collection is defined like Iterable but actually isn’t

    • Type: Icon: Bug Bug
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 4.1
    • Affects Version/s: None
    • Component/s: None
    • Labels:

       

      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

        1. PYTHON-3084.py
          5 kB
          Shane Harvey

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

              Created:
              Updated:
              Resolved: