skip and limit is not returning the right document (typescript)
See original GitHub issueDo you want to request a feature or report a bug? BUG
What is the current behavior? skip and limit is returning wrong documents, they are not what is expected
If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior? The expected behavior is, the skip should skip the document and show the right result,
How to reproduce the issue
-
Go to https://xxxxx/api/v1/trips?fields=name,ratingsAverage&paginate=1&limit=10 Above will return 9 docs. This is maximum number of docs I have.
-
Now use https://xxxxx/api/v1/trips?fields=name,ratingsAverage&paginate=1&limit=2 (1 st page) This will return 2 docs. Observe the name property.
-
Now use https://xxxxx/api/v1/trips?fields=name,ratingsAverage&paginate=2&limit=2( 2 nd page) This will return 2 docs. Observe the name property.
Try it for page 3 also.
You will notice that the trip name Forest Hiker
or The Sea explorer
or some name is repeating unnecessary.
So I am sometimes getting the same trip name. The trips name should not repeat, until, I start it from page 1 again.
Either the skip is not working properly, or there is bug in my code. I tried with raw mongo query, skip and limit works fine.
Pls take a look at tripsController.ts apiFeatures.ts
What are the versions of Node.js, Mongoose and MongoDB you are using? Note that “latest” is not a version. MongoDB 4,4 Mongoose 5.13.0 Node js 14.16.1
Issue Analytics
- State:
- Created 2 years ago
- Comments:7
I took a closer look and I can confirm this is expected behavior. Even with the MongoDB shell I get the ordering issue:
There’s no guarantee as to how the MongoDB server breaks ties when sorting. In addition to fixing your schema definition’s default
createdAt
, you should also add_id
to yoursort()
if you have a lot of ties and want to break them:@vkarpov15 . @IslandRhythms
Update: @vkarpov15 I got from your above comment and here. Thanks