payload icon indicating copy to clipboard operation
payload copied to clipboard

Limit behavior when using join fields

Open stofolus opened this issue 1 year ago • 2 comments

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 https://github.com/payloadcms/payload/blob/b1734b0d38ef653fb48f4c362d8e50bea76a3964/docs/queries/pagination.mdx?plain=1#L65
  • This doc show an example with limit together with pagination disabled https://github.com/payloadcms/payload/blob/b1734b0d38ef653fb48f4c362d8e50bea76a3964/docs/local-api/overview.mdx?plain=1#L150
  • 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 avatar Feb 14 '25 14:02 stofolus

🚀 This is included in version v3.26.0

github-actions[bot] avatar Mar 04 '25 15:03 github-actions[bot]

This issue has been automatically locked. Please open a new issue if this issue persists with any additional detail.

github-actions[bot] avatar Mar 12 '25 05:03 github-actions[bot]