Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

doc.cursor.id ~= cbson.uint(0) #21

Open
misschuer opened this issue May 3, 2018 · 5 comments
Open

doc.cursor.id ~= cbson.uint(0) #21

misschuer opened this issue May 3, 2018 · 5 comments

Comments

@misschuer
Copy link

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

@isage
Copy link
Owner

isage commented May 3, 2018

What?

@misschuer
Copy link
Author

sorry for

@misschuer
Copy link
Author

misschuer commented Jul 2, 2018

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.

@isage
Copy link
Owner

isage commented Jul 2, 2018

Can you provide an example of how you use aggregate, and what error it returns?

@misschuer
Copy link
Author

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,
},
}
},
}

This is copy from collection.lua

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

--############### i debug it here
ngx.log(ngx.ERR, "cursor_id = ", tostring(doc.cursor.id))
-- cursor
return cursor.new(self, {}, {}, false, doc.cursor.id):add_batch(doc.cursor.firstBatch)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants