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

Improve documentation on cursor slices

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 3.12, 4.0
    • Affects Version/s: None
    • Component/s: None
    • None

      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.

            Assignee:
            bernie@mongodb.com Bernie Hackett
            Reporter:
            bernie@mongodb.com Bernie Hackett
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved: