File tree 2 files changed +13
-1
lines changed
2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 20
20
21
21
.. describe :: c[index]
22
22
23
- See :meth: `__getitem__ `.
23
+ See :meth: `__getitem__ ` and read the warning .
24
24
25
25
.. automethod :: __getitem__
26
26
Original file line number Diff line number Diff line change @@ -616,6 +616,18 @@ def max_await_time_ms(self, max_await_time_ms):
616
616
def __getitem__ (self , index ):
617
617
"""Get a single document or a slice of documents from this cursor.
618
618
619
+ .. warning:: A :class:`~Cursor` is not a Python :class:`list`. Each
620
+ index access or slice requires that a new query be run using skip
621
+ and limit. Do not iterate the cursor using index accesses.
622
+ The following example is **extremely inefficient** and may return
623
+ surprising results::
624
+
625
+ cursor = db.collection.find()
626
+ # Warning: This runs a new query for each document.
627
+ # Don't do this!
628
+ for idx in range(10):
629
+ print(cursor[idx])
630
+
619
631
Raises :class:`~pymongo.errors.InvalidOperation` if this
620
632
cursor has already been used.
621
633
You can’t perform that action at this time.
0 commit comments