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

Pagination with mongoose unhandled doubling documents bug. #222

Open
lawuysal opened this issue Mar 23, 2024 · 2 comments
Open

Pagination with mongoose unhandled doubling documents bug. #222

lawuysal opened this issue Mar 23, 2024 · 2 comments

Comments

@lawuysal
Copy link

Since MongoDB does not keep documents in proper order, querying for the different pages can cause the same documents to appear in the query results. We should use a sort before the "skip()". Here is the StackOverflow answer.

@hoapooh
Copy link

hoapooh commented Nov 10, 2024

Can you paste your code here so that i can reference it please, i have tried my code like
this.query = this.query.sort({ createdAt: -1 }).skip(skip).limit(limit)
but it still give me the error, in mmy opinion i think this is the right way to get the latest data based on the descending of createdAt as Jonas set as an default value of "-createdAt" in the sort() function. Please correct me if i'm worng.

@lawuysal
Copy link
Author

Just use the way in the Stack Overflow link that I shared.

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