From fe9f378a1a3e45b6b7f26d806a96ff6618428bf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BA=91=E5=8D=8E?= <8852086@qq.com> Date: Wed, 6 May 2026 21:13:19 +0800 Subject: [PATCH] =?UTF-8?q?fixed:=20#1666=E9=94=99=E8=AF=AF=E7=9A=84?= =?UTF-8?q?=E7=A7=BB=E9=99=A4batchSize=20(#2151)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lualib/skynet/db/mongo.lua | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/lualib/skynet/db/mongo.lua b/lualib/skynet/db/mongo.lua index 541d33e8..23649984 100644 --- a/lualib/skynet/db/mongo.lua +++ b/lualib/skynet/db/mongo.lua @@ -627,6 +627,11 @@ function mongo_cursor:maxTimeMS(ms) return self end +function mongo_cursor:batchSize(amount) + self.__batchSize = amount + return self +end + local opt_func = {} local function opt_define(name) @@ -645,6 +650,7 @@ opt_define "skip" opt_define "limit" opt_define "hint" opt_define "maxTimeMS" +opt_define "batchSize" local function add_opt(self, opt, ...) if opt == nil then @@ -807,11 +813,16 @@ function mongo_cursor:hasNext() if self.__data == nil then local name = self.__collection.name response = database:runCommand("find", name, "filter", self.__query, "sort", self.__sort, - "projection", self.__projection, add_opt(self, "skip", "limit", "hint", "maxTimeMS")) + "projection", self.__projection, add_opt(self, "skip", "limit", "hint", "maxTimeMS", "batchSize")) else if self.__cursor and self.__cursor > 0 then local name = self.__collection.name - response = database:runCommand("getMore", bson_int64(self.__cursor), "collection", name) + local bz = self.__batchSize + if bz and bz > 0 then + response = database:runCommand("getMore", bson_int64(self.__cursor), "collection", name, "batchSize", bz) + else + response = database:runCommand("getMore", bson_int64(self.__cursor), "collection", name) + end else -- no more self.__document = nil