Skip to content

mongodb runCommand返回的数据 #1711

Answered by sanergogogo
sanergogogo asked this question in Q&A
Discussion options

You must be logged in to vote
local result = {}
local response = self.db[tablename]:aggregate(pipeline, options)
if response.ok ~= 1 then
    error(response["$err"] or "Reply from mongod error")
else
    result = response.cursor.firstBatch or response.cursor.nextBatch
    while response.cursor.id > 0 do
        response = self.db:runCommand("getMore", bson.int64(response.cursor.id), "collection", tablename)
        if response.ok ~= 1 then
            error(response["$err"] or "Reply from mongod error")
        end
        local document = response.cursor.firstBatch or response.cursor.nextBatch
        for index, value in ipairs(document) do
            table.insert(result, value)
        end
    end
    return result…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by sanergogogo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant