File tree Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Expand file tree Collapse file tree 2 files changed +13
-1
lines changed Original file line number Diff line number Diff line change 2020
2121 .. describe :: c[index]
2222
23- See :meth: `__getitem__ `.
23+ See :meth: `__getitem__ ` and read the warning .
2424
2525 .. automethod :: __getitem__
2626
Original file line number Diff line number Diff line change @@ -616,6 +616,18 @@ def max_await_time_ms(self, max_await_time_ms):
616616 def __getitem__ (self , index ):
617617 """Get a single document or a slice of documents from this cursor.
618618
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+
619631 Raises :class:`~pymongo.errors.InvalidOperation` if this
620632 cursor has already been used.
621633
You can’t perform that action at this time.
0 commit comments