From e30fdcca10c9677d2ff4995572d8bbc010bbabd5 Mon Sep 17 00:00:00 2001 From: xiyoo0812 Date: Thu, 2 Nov 2023 10:53:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B8=B4=E6=97=B6=E6=8F=90=E4=BA=A4=E4=BF=AE?= =?UTF-8?q?=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- script/driver/mongo.lua | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) diff --git a/script/driver/mongo.lua b/script/driver/mongo.lua index 17235e93..6da9c427 100644 --- a/script/driver/mongo.lua +++ b/script/driver/mongo.lua @@ -327,8 +327,8 @@ function MongoDB:drop_collection(co_name) end -- 参数说明 --- indexes: {{key={open_id, platform_id}, name="open_id-platform_id", unique=true} } --- indexes: {{key={open_id=1, platform_id=1}, name="open_id-platform_id", unique=true} } +-- indexes: {{key={open_id=1}, name="open_id", unique=true} } +-- indexes: {{key={open_id,1,platform_id,1}, name="open_id-platform_id", unique=true} } function MongoDB:create_indexes(co_name, indexes) for _, index in pairs(indexes) do index.key = self:format_pairs(index.key) @@ -389,19 +389,14 @@ function MongoDB:format_pairs(args, doc) if type(next(args)) == "string" then return args end - local array = {} - for _, key in pairs(args) do - array[#array + 1] = key - array[#array + 1] = 1 - end if doc then - array[#array + 1] = doc + args[#args + 1] = doc end - return bsonpairs(tunpack(array)) + return bsonpairs(tunpack(args)) end -- 参数说明 ---sort: {k1=1,k2=1} / {k1,k2,k3} +--sort: {k1=1} / {k1,1,k2,-1,k3,-1} function MongoDB:find(co_name, query, projection, sortor, limit, skip) local fsortor = self:format_pairs(sortor, self.sort_doc) local succ, reply = self:runCommand("find", co_name, "filter", query, "projection", projection, "sort", fsortor, "limit", limit, "skip", skip)