Update other collections with hook

default discord avatar
last month

I have a collection called 'Votes' where a user will vote on another location called 'Locations'. Each Vote will have a locationId and UserId. Would it be possible to update a total tally of votes in the related location collection after a vote document is created using a Hook? I'm not qutie sure if they're only intended for updating document in the same collection or not.

I'm thinking Sibling Data is what I need to use here:

import type { FieldHook } from 'payload/types';

// Field hook type is a generic that takes three arguments:

// 1: The document type

// 2: The value type

// 3: The sibling data type

type ExampleFieldHook = FieldHook<ExampleDocumentType, string, SiblingDataType>;

const exampleFieldHook: ExampleFieldHook = (args) => {

const {

value, // Typed as


as shown above

data, // Typed as a Partial of your ExampleDocumentType

siblingData, // Typed as a Partial of SiblingDataType

originalDoc, // Typed as ExampleDocumentType



} = args;

// Do something here...

return value; // should return a string as typed above, undefined, or null


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.