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

cannot sort cursor before limit #18

Open
keyleo opened this issue May 20, 2020 · 2 comments
Open

cannot sort cursor before limit #18

keyleo opened this issue May 20, 2020 · 2 comments

Comments

@keyleo
Copy link

keyleo commented May 20, 2020

Let us say, we have 1000 records, and I want to fetch latest 100 records by timestamp.

when i use
local r = col:find(criteria,nil,100)
r:sort({["timestamp"]=-1})

the cursor return sorted result of first 100 results.

what I want is sort 1000 records first, and then limit 100 records.

@sagrada1788
Copy link

it is a bug.
you can modify this file src/cursor.lua in line 42:

function cursor_methods:limit(n)
assert(n)
self.limit_n = n
return limit
end

modify

return limit

to

return self

@sagrada1788
Copy link

then use like this

r:sort({["timestamp"]=-1}):limit(100)

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