req.collection is undefined for AfterRead in FIELD HOOK (not collection hook)

default discord avatar
3 months ago

I'm writing a custom field with an AfterRead field hook (not collection hook), and I want to access the collection this hook is being run from. When I try to access


from the hook's arguments, it's undefined. When I try using collection hooks instead, the


is NOT undefined as expected.

Is there a way to access the collection in field hooks?

  • discord user avatar
    Payload Team
    3 months ago

    Looking into this right now!

    @bombnp Hm I cannot reproduce it. Tried adding an afterRead hook to a field, and


    works perfectly.

    Could you try creating a minimal reproduction using this guide:


    Specifically this is what I tried, and req.collection does exist here

  • default discord avatar
    3 months ago

    Wth I tried to create a minimal reproduction repo with the same code and it works fine.

    Then, I went back to my own project with the same code and it somehow works fine now without any changes. Maybe some shenanigans with nodemon i guess. Sorry for wasting your time

Open the post
Continue the discussion in Discord
Like what we're doing?
Star us on GitHub!


Connect with the Payload Community on Discord



Can't find what you're looking for?

Get help straight from the Payload team with an Enterprise License.