question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

limit doesn't work with sort

See original GitHub issue

The 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:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

3reactions
kavi87commented, Feb 21, 2017

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).

0reactions
pixelpaxcommented, Apr 14, 2018

@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?

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found