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.

Collection with slug can't by found on payload.findById - Payload 3.0 Beta

default discord avatar
cauacoelho9 months ago
1

Hello, I have a CMS made in Payload 2.0 where findById works perfectly, however in Payload 3.0 Beta findById complains that the collection slug does not exist



below is the error



ERROR: APIError: Collection with slug c_distributioncenter cannot be found. Find the operation.
    in findLocal (webpack-internal:///(rsc)/./node_modules/payload/dist/collections/operations/local/find.js:15:15)
    in BasePayload.find (webpack-internal:///(rsc)/./node_modules/payload/dist/index.js:79:16)
    in handleCreateOrUpdate (webpack-internal:///(rsc)/./src/collections/Suppliers/hooks/handleCreateOrUpdate.ts:24:79)
    in Suppliers.hooks.beforeChange (webpack-internal:///(rsc)/./src/collections/Suppliers/index.ts:45:95)
    in eval (webpack-internal:///(rsc)/./node_modules/payload/dist/collections/operations/create.js:127:26)


Below is my code using findById



const distributionCenter = await payload.findByID({
      collection: 'c_distributioncenter',
      id: id,
    })


It worked correctly! Thanks

  • discord user avatar
    alessiogr
    10 months ago

    This can happen if you do

    import payload from 'payload

    ' and use the imported payload for the local API



    Never do that



    Make sure to only use payload from req (req.payload) or from somewhere else where it gets passed through

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.