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

Limit behavior when using join fields #11187

Open
stofolus opened this issue Feb 14, 2025 · 0 comments · May be fixed by #10936
Open

Limit behavior when using join fields #11187

stofolus opened this issue Feb 14, 2025 · 0 comments · May be fixed by #10936
Assignees
Labels

Comments

@stofolus
Copy link
Contributor

Describe the Bug

When using MongoDB and setting a limit together with pagination: false it will behave differently if the collection has a join field or not.

  • Without a join field the limit is respected
  • With a join field the limit is ignored and the full result is returned

I think that the expected behavior is that limit should be ignored. It's a bit confusing though.

  • The docs mention here that the full result should be returned
    For `find` operations within the Local API, you can disable pagination to retrieve all documents from a collection by passing `pagination: false` to the `find` local operation.
  • This doc show an example with limit together with pagination disabled
    pagination: false, // If you want to disable pagination count, etc.
  • Payloads own code actually use them together https://github.com/search?q=repo%3Apayloadcms%2Fpayload+%22pagination%3A+false%22+%22limit%3A+1%22&type=code&p=2 But if that code is run on a collection with a join field it can return more results and it might produce unexpected results
  • Both mongoose-paginate-v2 & mongoose-aggregate-paginate-v2 have in their docs that [pagination] {Boolean} - If pagination is set to false, it will return all docs without adding limit condition. (Default: True)

I believe that the root cause is that mongoose-paginate-v2 actually does use the limit even if pagination is turned off. Which I would consider a bug.

Link to the code that reproduces this issue

https://github.com/stofolus/mongo-join-bug

Reproduction Steps

  • Start the project with a MongoDB instance
  • Go to /seed
  • Go to /

There are two collections where one have a join field and one does not. They should return the same information on the page.

Which area(s) are affected? (Select all that apply)

db-mongodb

Environment Info

Binaries:
  Node: 22.13.0
  npm: 11.0.0
  Yarn: N/A
  pnpm: 10.0.0
Relevant Packages:
  payload: 3.23.0
  next: 15.1.5
  @payloadcms/db-mongodb: 3.23.0
  @payloadcms/email-nodemailer: 3.23.0
  @payloadcms/graphql: 3.23.0
  @payloadcms/next/utilities: 3.23.0
  @payloadcms/payload-cloud: 3.23.0
  @payloadcms/richtext-lexical: 3.23.0
  @payloadcms/translations: 3.23.0
  @payloadcms/ui/shared: 3.23.0
  react: 19.0.0
  react-dom: 19.0.0
Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP Tue Nov 5 00:21:55 UTC 2024
  Available memory (MB): 30893
  Available CPU cores: 8
@stofolus stofolus added status: needs-triage Possible bug which hasn't been reproduced yet validate-reproduction labels Feb 14, 2025
@JarrodMFlesch JarrodMFlesch added the db: mongodb @payloadcms/db-mongodb label Feb 14, 2025
@github-actions github-actions bot removed the status: needs-triage Possible bug which hasn't been reproduced yet label Feb 14, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
3 participants