Hi everyone I have an issue.
Looking into the documentation I see this piece of code:
import type { CollectionConfig } from 'payload'
const MyCollection: CollectionConfig = {
slug: 'slug',
hooks: {
afterChange: [
async ({ context, doc, req }) => {
// return if flag was previously set
if (context.triggerAfterChange === false) {
return
}
await req.payload.update({
collection: contextHooksSlug,
id: doc.id,
data: {
...(await fetchCustomerData(data.customerID)),
},
context: {
// set a flag to prevent from running again
triggerAfterChange: false,
},
})
},
],
},
fields: [
/* ... */
],
}
However, when I try and run req.payload.update it returns an error "NotFound: Not Found" which is absolutely confusing.
I am aiming to create a afterChangeHook for videos, where I can use my custom made FfmpegService to convert videos into smaller quality for progressive video loading. Conversion is successful and I want to save the converted video data into Media collection, but for some reason req.payload.update throws that error.
I have attached docker log, and to translate from Croatian for convenience:
[FfmpegService] Video successfuly converted
[Video Hook] Updating Document
[Video Hook] ❌ Error occured: NotFound: Not Found