These are chat archives for Automattic/mongoose

Jun 2018
Renato Marinho
Jun 17 2018 09:58
This message was deleted
Jun 17 2018 10:00
Prefer MeisterTask
Makinde Adeagbo
Jun 17 2018 23:29
Is it possible to change the value of the result of a call to Query.findOne in a post hook? I'm trying to do authorization checks in a postfind hook. When the user isn't allowed to see the object that was returned, I want to return null. Right now I'm stuck just emptying out the object, but that breaks the current expectation of callers (since mongoose normally return null from findOne when there's no document.'findOne', async function postFindOne(doc) {
    await CheckCanSee(this, doc);

Right now, CheckCanSee checks permissions. if the document can't be seen, it removes all the keys from the object.

I've tried adding next to the hook's params and then calling it with next(null, null), but no dice. I've also tried just returning null from the hook function, but also no good.