Improve this documentation to more fully explain the implementation and pitfalls:
https://pymongo.readthedocs.io/en/stable/api/pymongo/cursor.html#pymongo.cursor.Cursor.__getitem__
Each slice requires a new query with a specific skip and limit. The cursor is cloned internally so as not to change the state of the top level Cursor object. The cursor does not keep an internal list with the entire result set, which would be an inefficient use of memory and may not even be possible depending on the size of the result set.
Warn (using the ..warning directive in Sphinx) users away from inefficient uses of this feature (though users may stumble upon this feature by accident). For example, warn users away from iteration patterns like:
cursor = db.coll.find() for idx in range(10): print(cursor[idx])
Each step through the loop above is a new query.
- is duplicated by
-
PYTHON-2861 Add documentation snippets warning against Cursor anti-patterns
- Closed