1. PyPA
  2. Python Packaging Authority Projects
  3. pypi
  4. Issues

Issues

Issue #89 wontfix

__getitem__ send limit(-1)

xbsura
created an issue

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.*.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?

Comments (3)

  1. Log in to comment