limit doesn't work with sort
See original GitHub issueThe following code shows how I query data from nedb:
db.find(newQuery).sort({ rent: -1}).skip((page - 1) * pageSize).limit(pageSize).exec((err, houses) => {
// deal with result
});
The query works fine at first time, it returns 10 records because pageSize
has been set to 10. However when page
changes to 2
, the query returns all the result.
First log:
query { rent: { '$gt': 0, '$lt': 99999999 } }
skip 0
limit 10
Second log:
query { rent: { '$gt': 0, '$lt': 99999999 } }
skip 10
limit 10
No idea why the second query returns all the result other than 10.
node: 0.10.31 nedb: 1.1.2 OS: OS X 10.10.2
Issue Analytics
- State:
- Created 8 years ago
- Reactions:1
- Comments:5 (2 by maintainers)
Top Results From Across the Web
how to fix Sort, limit and skip do not work on large amounts of ...
I am using pagination for mat-table and for that I have written mongoldb query as follows, but this query is not working for...
Read more >Excel Sort Limit - Microsoft Community
I have a spreadsheet with 100 rows of data. The sort was not working, so after much trial and error, I discovered that...
Read more >Order of $sort and $limit aggregation - MongoDB
Does the order of $skip and $limit matter in the pipeline? I use mongoose aggregation which runs a pipeline of operations.
Read more >LIMIT and ORDER BY in SQL Queries
By default, ORDER BY sorts in ascending order. When it comes to numbers, that means smallest first. If we want to find the...
Read more >MySQL ORDER BY LIMIT Performance Optimization - Percona
MySQL ORDER BY LIMIT is often the cause of MySQL performance problems. ... Sort by column in leading table if you have JOIN...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I thought there was an issue as well but the problem was type conversion. Be sure to pass numbers to the limit and skip methods and not a string (req.params values are string, most notably).
@kavi87 You’re my hero-- I ran into the exact same problem, also from req.params in express, thanks for posting the solution!
Seems like this would be a common mistake, the most common situation I can imagine using
limit
would make direct use of a query param. Perhaps nedb should raise an error when bogus types are passed into cursor functions @louischatriot ? Would you accept a PR doing this?