You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
next() - Returns the next single result set (as a table) in the results of a query operation.
result = cursor:next()
results() - Similar to the next method but returns an iterator function (as opposed to a table) that can be used in a for loop.
iterator = cursor:results()
has_more(in_current_batch)
has_more = cursor:has_more([bool])
in_current_batch: pass true to call moreInCurrentBatch (mongo >=1.5)
itcount()
it_count = cursor:itcount()
is_dead()
is_dead = cursor:is_dead()
is_tailable()
is_tailable = cursor:is_tailable()
has_result_flag()
has_result_flag = cursor:has_result_flag()
get_id()
id = cursor:get_id()
Example
localmongo=require('mongo')
-- query all the values in the namespace 'test.values' where a > 10localq1=assert(db:query('test.values', {a= {['$gt'] =10}}))
-- loop through the result setforresultinq1:results() doprint(result.a)
print(result.b)
end-- query all the values in the namespace 'test.values' where a < 10 (JSON version)localq2=assert(db:query('test.values', "{'a': {'$lt': 10}}"))
localresult=q2:next()
whileresultdoprint(result.a)
print(result.b)
result=q2:next()
end