Simplify your stack and build anything. Or everything.
Build tomorrow’s web with a modern solution you truly own.
Code-based nature means you can build on top of it to power anything.
It’s time to take back your content infrastructure.

@payloadcms/next-payload relationship hasMany field fails with more than 22 items

default discord avatar
paradox52702 years ago

Hi guys, I facing an issue in the @payloadcms/next-payload package where Payload fails when I add more than 22 items in a relationship, has many field. The error I got is:



[09:09:45] ERROR (payload): CastError: Cast to ObjectId failed for value "{
  '0': '64673cbe7b43c50c05008b9b',
  '1': '64673cbe7b43c50c05008ba5',
  '2': '64673cbc7b43c50c05008b73',
  '3': '64673cbd7b43c50c05008b91',
  ...
  ...
  '19': '64673cc27b43c50c05008c09',
  '20': '64673cc27b43c50c05008c13',
  '21': '64673cc37b43c50c05008c1d'
}" (type Object) at path "_id" for model "examples"
    at model.Query.exec (webpack-internal:///(api)/./node_modules/mongoose/lib/query.js:4155:23)
    at Function.paginate (/Users/wilsonle/tmp/my-app/node_modules/mongoose-paginate-v2/dist/index.js:158:51)
    at find (webpack-internal:///(api)/./node_modules/payload/dist/collections/operations/find.js:106:30)
    at runMicrotasks (<anonymous>)
    at processTicksAndRejections (node:internal/process/task_queues:96:5)
    at async handler (webpack-internal:///(api)/./node_modules/@payloadcms/next-payload/dist/handlers/[collection]/index.js:37:36)


I have went ahead and create an issue in the @payloadcms/next-payload repo:

https://github.com/payloadcms/next-payload/issues/31

Here's the link to the simple reproducible code:

https://github.com/WilsonLe/payload-next-bug-repro

Anyone know why this might be the case? This only happens to Payload attached to a NextJS project. A standalone Payload project works fine.

    Star on GitHub

    Star

    Chat on Discord

    Discord

    online

    Can't find what you're looking for?

    Get dedicated engineering support directly from the Payload team.