From d5c0d687b3111a3a88c16f4c74b31e4f1cc36740 Mon Sep 17 00:00:00 2001 From: Cloud Wu Date: Mon, 6 Nov 2017 20:51:33 +0800 Subject: [PATCH] positive limit support --- lualib/skynet/db/mongo.lua | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/lualib/skynet/db/mongo.lua b/lualib/skynet/db/mongo.lua index 4ed05281..c28766af 100644 --- a/lualib/skynet/db/mongo.lua +++ b/lualib/skynet/db/mongo.lua @@ -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