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:
Attachments
Issue Links
- is related to
-
PYTHON-3184 Collection should raise an error for non-string collection names
-
- Backlog
-
- links to