Open misschuer opened 6 years ago
What?
sorry for
when i use 'aggregate' to search data, then program runs err. so i explain the code, then i found 'doc.cursor.id' is not equal to cbson.uint(0) forever. i changed the 'doc.cursor.id' to 'cbson.uint(doc.cursor.id)' and it runs well. is this a bug or i use it in wrong way? it is in collection.lua line 372. forgive my poor english.
Can you provide an example of how you use aggregate, and what error it returns?
the pipeline: local wheres = { [ 1 ] = { ["$match"] = { guid = guid, } }, [ 2 ] = { ["$sort"] = { _id = -1, }, }, [ 3 ] = { ["$skip"] = skips, }, [ 4 ] = { ["$limit"] = limits, }, [ 5 ] = { ["$lookup"] = { from = user_table_name, localField = "guid", foreignField = "_id", as = "docs1", } }, [ 6 ] = { ["$project"] = { _id = 1, guid = 1, docs1 = { name = 1, avatar = 1, }, } }, }
function _M.aggregate(self, pipeline, opts) local opts = opts or {} opts.pipeline = pipeline if not opts.explain then opts.cursor = {} end
local doc, err = self._db:cmd( { aggregate = self.name }, opts ) if not doc then return nil, err end
if opts.explain then return doc end
-- collection if opts.pipeline[#opts.pipeline]['$out'] then return self.new(opts.pipeline[#opts.pipeline]['$out'], self._db) end
the log file said 2018/07/12 20:52:15 [error] 27564#27564: 539 [lua] collection.lua:372: aggregate(): cursor_id = 0 2018/07/12 20:52:15 [error] 27564#27564: 539 [lua] utils.lua:425: print_err_format(): err : wrong cursor id
then i debug in cursor.lua function _M.next(self) ...... ngx.log(ngx.ERR, tostring(self._id)) if (not self._started) and (self._id == cbson.uint(0)) then ....... elseif #self._docs == 0 and self._id ~= cbson.uint(0) then ---############## Notice: because self._id is always 0 not eq to cbson.uint(0), it runs this logical and then throwed 'wrong cursor id' exception
if check_bit(flags, 0) then -- QueryFailure
return nil, "wrong cursor id"
end
elseif #self._docs == 0 then--or self._id == cbson.uint(0) then return nil, "no more data" end ..... end
function _M.aggregate(self, pipeline, opts) .............................. -- cursor return cursor.new(self, {}, {}, false, doc.cursor.id):add_batch(doc.cursor.firstBatch) end
OR
function _M.aggregate(self, pipeline, opts) .............................. -- cursor return cursor.new(self, {}, {}, false, cbson.uint(doc.cursor.id)):add_batch(doc.cursor.firstBatch) end