Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-11815

__getitem__ send a limit of -1

    XMLWordPrintableJSON

Details

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: Major - P3 Major - P3
    • None
    • 2.2.4, 2.4.8
    • Sharding
    • None
    • mongodb 2.2.4
    • Sharding
    • ALL

    Description

      db.collection.find().limit(-1) and db.collection.find().limit(1) is equivalent in mongo 2.4.7,but our mongo being used is 2.2.4.We found that sometimes limit(-1) is different with limit(1) when querying.
      in pymongo,the function _getitem_ send a limit of -1 when getting one document:

      if isinstance(index, (int, long)):
      if index < 0:
      raise IndexError("Cursor instances do not support negative"
      "indices")
      clone = self.clone()
      clone.skip(index + self.__skip)
      clone.limit(-1) # use a hard limit
      for doc in clone:
      return doc
      raise IndexError("no such item for Cursor instance")
      raise TypeError("index %r cannot be applied to Cursor "
      "instances" % index)
      In large skip,mongo return null,which is expected to return one document. After changing limit(-1) to limit(1),we got correct result. I consider limit(-1) is a bug,or does it exist something i did not realized?

      Attachments

        Activity

          People

            backlog-server-sharding [DO NOT USE] Backlog - Sharding Team
            xbsura xbsura
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: