__getitem__ send a limit of -1

XMLWordPrintableJSON

    • Type: Bug
    • Resolution: Done
    • Priority: Major - P3
    • None
    • Affects Version/s: 2.2.4, 2.4.8
    • Component/s: Sharding
    • None
    • Environment:
      mongodb 2.2.4
    • Sharding
    • ALL
    • None
    • 3
    • None
    • None
    • None
    • None
    • None
    • None

      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?

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

              Created:
              Updated:
              Resolved: