limit doesn’t work with sort

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

1 possible answer(s) on “limit doesn’t work with sort

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