positive limit support

This commit is contained in:
Cloud Wu
2017-11-06 20:51:33 +08:00
parent 57f08426ee
commit d5c0d687b3

View File

@@ -574,10 +574,20 @@ function mongo_cursor:hasNext()
if ok then
if doc then
self.__document = result.result
local doc = result.result
self.__document = doc
self.__data = result.data
self.__ptr = 1
self.__cursor = cursor
local limit = self.__limit
if cursor and limit > 0 then
limit = limit - #doc
if limit <= 0 then
-- reach limit
self:close()
end
self.__limit = limit
end
return true
else
self.__document = nil
@@ -615,11 +625,11 @@ function mongo_cursor:next()
end
function mongo_cursor:close()
-- todo: warning hasNext after close
if self.__cursor then
local sock = self.__collection.connection.__sock
local pack = driver.kill(self.__cursor)
sock:request(pack)
self.__cursor = nil
end
end